Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Which principle(s) in Collection (HashSet) am I violating ?

 
Eric Janssens
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know why the last test fail (HashSet fail to see that it contains the object modified because it regroup first by hashcode during the initial add) but I dont know which principle(s) I am violating in this code.

I have few ideas but nothing sure.
Does the Collection classes are intended to be use only with immutable objects?

Sorry if this topic have already been address. It s hard to find a relevent topic with those keywords.


[ September 23, 2006: Message edited by: Eric Janssens ]
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the API for Set: "Note: Great care must be exercised if mutable objects are used as set elements. 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."
 
Eric Janssens
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had look the Collection and HashSet classes in the API but didnt take a look to the Set interface.

Thanks a lot!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic