简体   繁体   English

本机Java方法是否等同于静态Java方法?

[英]Are native Java methods equivalent to static Java methods?

I am rewriting some native methods as regular Java methods. 我正在重写一些本机方法作为常规Java方法。

Are native methods effectively static? 本机方法是否有效静态? Or is there ever a case where they have an implicit 'this' parameter? 或者有没有他们有一个隐含的'this'参数的情况?

Thanks! 谢谢!

Native methods can be static or non- static , just like regular Java methods. 本机方法可以是static或非static ,就像常规Java方法一样。

Non- static native methods receive this reference, static ones receive a reference to containg class instead. static本机方法接收this引用, static方法接收对包含类的引用。

From JNI Specification : 来自JNI规范

Native Method Arguments 本机方法参数

The JNI interface pointer is the first argument to native methods. JNI接口指针是本机方法的第一个参数。 The JNI interface pointer is of type JNIEnv. JNI接口指针的类型为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类的引用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM