Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm looking for the algorithm of Object.hashCode().

This code is native in Object.java.

Is this because

(a) the code is in assembly-- never was in Java or any other HLL at all

or

(b) it simply isn't disclosed

?

In either case, I am looking to get hold of the algorithm (pseudo-code or some detailed explanation) of "how hashCode() is calculated"-- what are the params going into its calculation and the calculation itself?

Please note: It's the hashCode() of Object i'm looking for-- not another like that of String or hashMap/table.

//==========================================================================

the new Java docs-- jdk 8 now saying

"The value returned by hashCode() is the object's hash code, which is the object's memory address in hexadecimal." 
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
269 views
Welcome To Ask or Share your Answers For Others

1 Answer

Native hashCode method implementation depends on the JVM. By default in HotSpot it returns random number, you can check it in the source code (function get_next_hash)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...