Is the naming convention for java native interface method and module name?

做~自己de王妃 提交于 2019-12-01 00:19:56

From Oracle's documentation:

Dynamic linkers resolve entries based on their names. A native method name is concatenated from the following components:

  • the prefix Java_
  • a mangled fully-qualified class name
  • an underscore (_) separator
  • a mangled method name
  • for overloaded native methods, two underscores (__) followed by the mangled argument signature

So if you have the following:

package com.foo.bar;

class Baz {
    public native void Grill(int i);
}

Then the corresponding C function should be:

JNIEXPORT void JNICALL Java_com_foo_bar_Baz_Grill(JNIEnv *env, jobject thiz, jint i);

If you have an underscore in the Java method name:

public native void A_Grill(int i);

Then the C function would be:

JNIEXPORT void JNICALL Java_com_foo_bar_Baz_A_1Grill(JNIEnv *env, jobject thiz, jint i);

The _1 escape sequence matches the _ in A_Grill.

You're free to call your package and class and methods whatever you like at the Java level, subject to the rules of the language, but the naming convention at the C level is completely defined by the output of the javah tool.

You can call the shared library whatever you like as well subject to filename rules and the rules of ’System.load()/loadLibrary()`.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!