Always worth checking out the examples at http://javaalmanac.com
A quick glance comes up with
http://javaalmanac.com/egs/java.lang/GetHash.html
 
Kind regards
Jase
 

---
Jason Bell

-----Original Message-----
From: abhay [mailto:[EMAIL PROTECTED]]
Sent: 30 December 2002 03:40
To: JDJList
Subject: [jdjlist] hashCode ??

Hello,

Just a small doubt. Has anybody ever used hashCode() ... the java.lang.Object provides ?
To be honest i dont know how to use this in our applications .
(Can anybody suggest any way to use hashCode() ? )

The API says ...

"As much as is reasonably practical, the hashCode method defined by class Object does return distinct integers for distinct objects. (This is typically implemented by converting the internal address of the object into an integer, but this implementation technique is not required by the JavaTM programming language.) "

So can we safely assume that its the address of the object in memory ? (a pointer in C or C++)
So if java a developer need not be concerned about pointers, what is this method doing here ?

What is more striking is that the API says ..
"If two objects are equal according to the equals(Object) method, then calling the hashCode method on each of the two objects must produce the same integer result"

This means if you have a two objects with equal values inside (for instance ..
    String str1 = new String("Abhay");
    String str2 = new String("Abhay");

and if hashCode() returns the address then does it means that these 2 objects are physically one and
the same in the memory ? I dont get it ...

Please share your knowledge..

Thanks.

regards
abhay  kulkarni
  ____________________________________________________
To change your JDJList options, please visit:
http://www.sys-con.com/java/list.cfm

Be respectful! Clean up your posts before replying
____________________________________________________

____________________________________________________
To change your JDJList options, please visit:
http://www.sys-con.com/java/list.cfm

Be respectful! Clean up your posts before replying
____________________________________________________

Reply via email to