Reputation: 1469
I made an own class called Region and I store instances of Region in a HashSet. I use a HashSet, that there are no Objects which are equal in the list. The String name of a Region should be unique in the HashSet, so I have overriden the equals method.
My Question:
What happens if I store two regions with different names into the HashSet and then I make the different names equal (by a setter for the name)?
This is no duplicate. The other question is about equal HashSets and not about equal objects in HashSets.
Upvotes: 4
Views: 225
Reputation: 198341
The behavior of a set is not specified if the value of an object is changed in a manner that affects equals comparisons while the object is an element in the set.
-- the Set Javadoc
Upvotes: 5