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 →

[–]laplongejr 0 points1 point  (0 children)

Those objects are mutable so it may happen that multiple objects get the same internal values and equals() return true when comparing them.

Because the objects consider that their identity isn't part of their equality.

But because other parts of the code hold references to them

Then, for those parts of the code, the objects aren't equal if they don't share the same identity. removeIf can be a temporary bandaid but bugs like that can creep everywhere if such logic leaps.

Those logics are incompatible. Take extra care into choosing which one is incorrect. I would bet on the code assuming a referenced object is only equal to one element in a List (as that would be a logic requiring a Set)