为什么哈希code()和的getClass()本地方法? [英] Why are hashCode() and getClass() native methods?
问题描述
我检查对象
类的源$ C $ C,我发现中的方法声明的getClass()
是
I checked the source code of Object
class where I found that method declaration of getClass()
was
public final native Class<?> getClass();
和散code的声明()
是
public native int hashCode();
为什么这两种方法本地
类中的方法,我怎么能得到这些方法的源$ C $ C?
Why are these two methods native
methods in the class and how can I get the source code of those methods?
推荐答案
您可以找到的本地方法的完整源$ C $ C的这里
You can find the complete source code of the native methods here
我希望这会为你工作。
这是本地方法,因为它必须与机器交互。在这里,机器相关的code被写入在C语言中,这是不符合的源代码包或的rt.jar
的 LIB <降临/ code> Java运行时环境(JRE)的位置。
These are native methods, because it has to interact with the machine. Here machine dependent code is written in the C language, which is not coming with the source package or in rt.jar
of the lib
location of the Java Runtime Environment (JRE).
还有一个原因是本机可能是在性能方面的原因。由于可以通过C级编程性能可能有所提高,因此,他们可能已经写入本地code在C语言中。
One more reason for being native is possibly for the performance reasons. Due to the C level programming performance may be improved, hence they may have written the native code in the C language.
该方法,因为它们涉及本地数据是本地人。在散code
方法返回依赖于指针的内部重新presentation堆中的对象的整数值。在的getClass
方法必须访问内部 VTBL
(虚函数表)的重新presents编译程序的类层次结构。这些都不是可能的Java核心。
The methods are native because they concern native data. The hashCode
method returns an integer value dependent on the internal representation of a pointer to an object on the heap. The getClass
method must access the internal vtbl
(virtual function table) that represents the compiled program's class hierarchy. Neither of these is possible with core Java.
这篇关于为什么哈希code()和的getClass()本地方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!