How is the hashCode () method implemented in the Object class?

Possible duplicate:
What is the implementation of hashCode in a java object?

While I was looking at the Object class, I found that there was only a declaration of the hashCode () method. Where is the implementation part? If there is no implementation, how does the hashCode () method return me the result?

+5
source share
4 answers

It is implemented in native code. As for the implementation, this is a little more complicated - you can change the default implementation. If you look at the sources of "Open JDK", you will see the following options:

-XX: hashCode = n (0 to 5).

  • 0 - RNG Park-Miller (default)
  • 1 - address function and some global state
  • 2 - const 1
  • 3 - sequential counter
  • 4 - object address
  • 5 - xor-shift

: http://hg.openjdk.java.net/jdk7/jdk7/hotspot/file/tip/src/share/vm/runtime/synchronizer.cpp

static inline intptr_t get_next_hash().

+10

native , (JVM).

+7

hashcode

public native int hashCode();

native , jvm-.

+5

?

. . .

, hashCode() ?

However, if you create a custom type, you are responsible for creating a value intthat is a good representation of the current state of the objects. Here is a good example of this.

0
source

All Articles