Providing a hash key which may be used for object identification, for example in
Hashtable and Map
of the Collections Framework/API
(http://java.sun.com/products/jdk/1.2/docs/guide/collections/).
This is explained in the java.lang.Object section of the API documentation. Try doing
your own
work next time.
--- abhay <[EMAIL PROTECTED]> wrote:
> 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
> ____________________________________________________
>
=====
Mark Zawadzki Performance Engineer/DBA/Programmer extraordinaire� [EMAIL PROTECTED]
[EMAIL PROTECTED]
"Democracies die behind closed doors," - Judge Damon Keith
"The people of this country, not special interest big money, should be
the source of all political power. Government must remain the domain of
the general citizenry, not a narrow elite." - Sen. Paul Wellstone
__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com
____________________________________________________
To change your JDJList options, please visit:
http://www.sys-con.com/java/list.cfm
Be respectful! Clean up your posts before replying
____________________________________________________