Thank you very much to all those who replied to this post
Thank you very much.

regards
abhay

"U. Penski" wrote:

 Hello,
-----Original Message-----
From: abhay [mailto:[EMAIL PROTECTED]]
Sent: Monday, December 30, 2002 4:40 AM
To: JDJList
Subject: [jdjlist] 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 ? 

not safely - watch the word "typically" !

Early versions of the Windows memory handler (AFAIK at least versions 3.0 and 3.1) allowed the handle of an allocated fixed memory block to contain its physical adress in memory.

There was expressively no guarantee for the programmer that later versions still use this technique

(should be the same in this case).

>...

>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.. 

duplicate string elimination is an old subject (e.g. since Borland C++ 4.x or earlier) and has already been discussed 

months or even years ago in this newsgroup  for the Java world (***).

If you use 

Map table=new HashMap();

and table.put( ...)  for duplicate objects (with the same content) then these objects should be referred to with ONE  integer (adress or handle - depending on implementation).

Outside HashMap usage the two strings (str1 and str2) might still have 2 - visible or invisible - memory adresses (see *** above)

regards,
U. Penski

[EMAIL PROTECTED]

[ sorry to all the firewalls out there that I have to use Outlook again to send this eMail - my Outlook Express installation currently probably dreams about a better memory handler ]

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

Be respectful! Clean up your posts before replying
____________________________________________________


 
 

--
regards
abhay  kulkarni
*************************************
"whatever is said in Latin sounds profound"
*************************************
  ____________________________________________________
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