Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Is value returned by java.lang.Object.hashCode( ) unique?

807580Feb 1 2010 — edited Feb 2 2010
Can 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?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 2 2010
Added on Feb 1 2010
24 comments
807 views