What is a native implementation in Java?

See English answer > what is the native keyword in Java for? 9

public native int hashCode()
protected native Object clone()

What are these locals? How do these methods work?

Solution

These methods are written internally or in "native" code outside Java, that is, specific to a given machine

You mentioned a part of intrinsic and JDK, but you can also write your own native methods using Java Native Interface (JNI) This usually uses C to write methods, but many other languages (such as Python) allow you to write methods in a fairly easy way The code is written in this way, either to improve performance or because it requires access to platform specific infrastructure that cannot be completed in normal Java

In the case of hashcode (), this is implemented by the JVM This is because hash codes are usually only related to what the JVM knows On earlier JVMs, this was related to the location of objects in memory – on other JVMs, objects may move in memory, so more complex (but still very fast) schemes can be used

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>