You get absurb results. The hashCode() of objects is not meant to be unique. It is a waste of time maintaining such code which uses Object.hashCode() as a key to retrieve results. Just find another way to generate those keys.
Here is the general contract for the method from the Javadoc
"The general contract of
Focussing on the last point, we can see that hashCode() is not meant to be distinct. Two or more objects can return the same hashCode() so please don't use it as a key.
This blog suggests using the SHA to generate keys and GIT uses them or may be use UUIDs. Duh!!
Here is the general contract for the method from the Javadoc
"The general contract of
hashCode is:
- Whenever it is invoked on the same object more than once during
an execution of a Java application, the
hashCodemethod must consistently return the same integer, provided no information used inequalscomparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application. - If two objects are equal according to the
equals(Object)method, then calling thehashCodemethod on each of the two objects must produce the same integer result. - It is not required that if two objects are unequal
according to the
equals(java.lang.Object)method, then calling thehashCodemethod on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables. "
Focussing on the last point, we can see that hashCode() is not meant to be distinct. Two or more objects can return the same hashCode() so please don't use it as a key.
This blog suggests using the SHA to generate keys and GIT uses them or may be use UUIDs. Duh!!