aspose file tools*
The moose likes Java in General and the fly likes Which principle(s) in Collection (HashSet) am I violating ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Which principle(s) in Collection (HashSet) am I violating ?" Watch "Which principle(s) in Collection (HashSet) am I violating ?" New topic
Author

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

Eric Janssens
Ranch Hand

Joined: Sep 26, 2005
Posts: 53
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

Joined: Jan 30, 2000
Posts: 18671
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."


"I'm not back." - Bill Harding, Twister
Eric Janssens
Ranch Hand

Joined: Sep 26, 2005
Posts: 53
I had look the Collection and HashSet classes in the API but didnt take a look to the Set interface.

Thanks a lot!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Which principle(s) in Collection (HashSet) am I violating ?