Is value returned by java.lang.Object.hashCode( ) unique?
807580Feb 1 2010 — edited Feb 2 2010Can hashCode( ) return the same value for 2 different objects, given that I have not overridden this API in my objects?
The documentation for hashCode says "This is typically implemented by converting the internal address of the object into an integer". I wanted to know the actual implementation of this API in the sun JVM.
Also I wnated to know the outcome of the following:
1. Object A is in location X
2. A.hashCode( ) is invoked.
3. Garbage collector moves A from X to location Y
4. Object B is created in location x
5. B.hashCode( ) is invoked.
Are the hash codes in the above case always same?