Hi ranchers,
Ernest Friedman-Hill posted November 29, 2006 11:39 AM
If the pile-sorting step maps equal keys into different buckets -- as is likely in the scenario you describe -- then the equals comparison will never even be done between the two keys.
and Henry Wong posted November 29, 2006 11:42 AM
The reason you can add more than one is because they are going into different buckets. And there is no reason to check whether two objects, in two different buckets, are equal or not.
Ah, yes!
I forgot that the hashCode / bucket step will be performed first. Before the equals. And with a 1 Mio : 1 chance, the bucket will contain only one animal.
If nothing else is in the bucket, then there will be no equals
test at all. And the animal (presumably unique) added to the set.
Thanks for your replies,
Bu.