Hallo I have the following class
I want to add instances of this class to a TreeSet.
As far I have understood Sets
you should be able to add an element which is not already contained in this set. To
test this the equals() method is used.
When I try to put two different instances of the above class, which differ only in the jarFile field but have the same name value (compareTo returns 0) only the first instance is put into the TreeSet.
When I switch to a HashSet both instances are put into the Set.
Output:
This is totally unexpectated behavior for me, since I thought that only equals() is used to determined if an instance can be put into a Set, and compareTo() is only used for ordering.
Can anybody explain this behavior???
Many thanks,
Hans