问题描述
我正在将一些本机方法重写为常规Java方法。
I am rewriting some native methods as regular Java methods.
本机方法是否有效静态?或者有没有他们有隐含'this'参数的情况?
Are native methods effectively static? Or is there ever a case where they have an implicit 'this' parameter?
谢谢!
推荐答案
原生方法可以 static
或非 - static
,就像常规Java方法一样。
Native methods can be static
or non-static
, just like regular Java methods.
非 - static
本机方法接收此
引用,静态
接收的改为引用类别的引用。
Non-static
native methods receive this
reference, static
ones receive a reference to containg class instead.
来自:
JNI接口指针是本机方法的第一个参数。 JNI接口指针的类型为JNIEnv。第二个参数根据本机方法是静态方法还是非静态方法而有所不同。非静态本机方法的第二个参数是对该对象的引用。静态本机方法的第二个参数是对其Java类的引用。
The JNI interface pointer is the first argument to native methods. The JNI interface pointer is of type JNIEnv. The second argument differs depending on whether the native method is static or nonstatic. The second argument to a nonstatic native method is a reference to the object. The second argument to a static native method is a reference to its Java class.
这篇关于本机Java方法是否等同于静态Java方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!