Answer the question
In order to leave comments, you need to log in
implementation of hashCode(); in class Object (Java)
Good evening everyone!
I wanted to ask where you can find the implementation
public native int hashCode();
from class Object? The platform doesn't matter. It just became interesting, but googling really did not give anything. Answer the question
In order to leave comments, you need to log in
The OpenJDK source code can be downloaded from openjdk.java.net/
People have already asked this question blogs.tedneward.com/CommentView ,guid,eca26c5e-307c-4b7c-931b-2eaf5b176e98.aspx, I think this is the right direction.
Look at the method definition. There the keyword native costs. This means that the implementation is written in C.
And most likely depends on the execution platform.
There is a JNI mechanism for this.
Well, I will give a link to the official documentation.
For myself, I understand that for a simple Object, the address of the object reference in memory is encoded in hashCode.
Here I found not the implementation itself, but an explanation of its principle:
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.)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question