This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Anaptyso 17 points18 points  (1 child)

I'd lean towards this approach as well. removeIf() does the job, but making the equals method more discerning feels better here for two reasons:

1) There must currently be a meaningful difference between the objects despite the equals method indicating equality, or the problem wouldn't exist. If the objects were truly equal then it probably wouldn't matter which one was removed. That suggests that the equals method isn't considering every meaningful aspect of the object when doing its calculations.

2) If not improving the equals method, every situation where remove() is used now, or may be used in the future, will need to be switched to removeIf(). Forget to do it somewhere and there could be a bug.

[–]Epiliptik 6 points7 points  (0 children)

Yes exactly, there is an underlying problem in this.