[gclist] object hash codes and copying collection

Bryan O'Sullivan bos@serpentine.com
Wed, 10 Dec 1997 08:49:45 -0800 (PST)

e> My understanding of the Java hashCode feature is that it must meet
e> these hard requirements:
e>   - Every object has a UNIQUE hash code

This is incorrect, and would not be very reasonable if it were true.

e>   - An object's hash code never changes during the object's
e>     lifetime

Right.  The other general expectation of an object's hash code in Java
is that if two objects are "the same" according to Object.equals, they
should have the same hash code.

e>   - Object hash codes are distributed such that one can find hash
e>     functions over the hash codes that distribute the objects into
e>     hash bins uniformly (with high probability).

This is, unfortunately, a very soft requirement indeed.  Scrutiny of
many of the classes in the standard JDK1.1 java.* classes reveals what
might generously be called questionable choices of hash code
generators in several instances.