Why hashCode() returns the same value for a object in all consecutive executions?

Posted by Vijay Shanker on Stack Overflow See other posts from Stack Overflow or by Vijay Shanker
Published on 2010-06-06T07:24:49Z Indexed on 2010/06/06 7:32 UTC
Read the original article Hit count: 107

Filed under:
|

Hi,

I am trying some code around object equality in java. As I have read somewhere

hashCode() is a number which is generated by applying the hash function. Hash Function can be different for each object but can also be same. At the object level, it returns the memory address of the object.

Now, I have sample program, which I run 10 times, consecutively. Every time i run the program I get the same value as hash code.

If hashCode() function returns the memory location for the object, how come the java(JVM) store the object at same memory address in the consecutive runs?

Can you please give me some insight and your view over this issue?

© Stack Overflow or respective owner

Related posts about java

Related posts about equality