Saurabh Pillai wrote:Ivan, UseCodeTags
When you add to HashSet it calls to equals method. http://docs.oracle.com/javase/7/docs/api/java/util/HashSet.html#add%28E%29
Can you show us your SongBad class?
Saurabh Pillai wrote:
When you add to HashSet it calls to equals method
Ivan Turner wrote:
I don't exactly understand what's going on here. The text says "If the add() method returns false, you know the new object was a duplicate of something already in the set.
I'm new and quick on the draw. I did some detailed reading on pp 561 and found something like this: "Override hashcode() with a custom version to make sure the objects have the same value. HashSet finds a matching hashcode for two objects, HashSet will call one of the object's equal() methods to see if these hashcode-matched objects really ARE equal."
I do some of my very best work in water. Like this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
|