Are native Java methods equivalent to static Java methods?(本机 Java 方法是否等同于静态 Java 方法?)
问题描述
我正在将一些本机方法重写为常规 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?
谢谢!
推荐答案
Native 方法可以是 static
或非 static
,就像常规 Java 方法一样.
Native methods can be static
or non-static
, just like regular Java methods.
非static
原生方法接收 this
引用,static
则接收对包含类的引用.
Non-static
native methods receive this
reference, static
ones receive a reference to containg class instead.
来自 JNI 规范:
本机方法参数
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 方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:本机 Java 方法是否等同于静态 Java 方法?


- 如何使 JFrame 背景和 JPanel 透明且仅显示图像 2022-01-01
- java.lang.IllegalStateException:Bean 名称“类别"的 BindingResult 和普通目标对象都不能用作请求属性 2022-01-01
- 获取数字的最后一位 2022-01-01
- 未找到/usr/local/lib 中的库 2022-01-01
- 如何指定 CORS 的响应标头? 2022-01-01
- 将 Java Swing 桌面应用程序国际化的最佳实践是什么? 2022-01-01
- 在 Java 中,如何将 String 转换为 char 或将 char 转换 2022-01-01
- 转换 ldap 日期 2022-01-01
- Eclipse 的最佳 XML 编辑器 2022-01-01
- GC_FOR_ALLOC 是否更“严重"?在调查内存使用情况时? 2022-01-01