Rauhl Roy wrote:My understanding is that from the effective java link mentioned above that, hashing checks if equals() and hashcode() contract is met or not. if met hashing is done otherwise hashing fails?
I don't think so; the only things I've ever read are:
1. If you implement
equals(), you should
also implement
hashCode().
2. If object A is
equal() to object B then they
must return the same hashcode.
(That is NOT the same as saying that two objects, A and B, that return the same hashcode must be
equal() - in fact, such a guarantee is pretty well impossible).
3. It generally helps for hashed collections if,
as far as possible, objects that are NOT
equal() produce different hashcodes.
Winston
BTW - You may be interested to know that HashSet and HashMap actually "re-hash" your hash to help prevent bucket collisions, so you don't even need to worry
too much about "hash spread"; just make sure that they're likely to be distinct.