Can the hashcode of the two objects be the same?
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   anu_singh
Posted On:   Monday, April 5, 2004 01:48 AM

Can the hashcode of the two objects be the same?

Re: Can the hashcode of the two objects be the same?

Posted By:   Anonymous  
Posted On:   Monday, April 5, 2004 09:18 AM

2 good places to read more about hashCode() method:

1. Java API, look under java.lang.Object

2. Grab this book & read, Effective Java by Joshua Bloch, Chapter 3, Item 8.

Re: Can the hashcode of the two objects be the same?

Posted By:   Christopher_Koenigsberg  
Posted On:   Monday, April 5, 2004 06:27 AM

Yes.


In fact there have to be a lot of different objects sharing the same hashcodes, if you compare the size of the possible values (number of possible objects vs. number of possible hashcode values).


I think that all you can really know for sure (cf the Java Languages spec) is, IF two variables point to the SAME object, then their hashcodes must return the same value. That's the only guarantee.

About | Sitemap | Contact