Java本机接口方法和模块名称的命名约定是什么? [英] What is the naming convention for java native interface method and module name?

查看:59
本文介绍了Java本机接口方法和模块名称的命名约定是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我完全可以按照jni教程进行操作.但是,当我更改方法名称时,就会遇到麻烦.我需要遵循一个命名约定吗?本教程使用HelloJNI作为模块名称和库名称.我使用了"useaaacom".

I am able to follow a jni tutorial just fine. But when I change the method name, I run into trouble. Is there a naming convention I need to follow? The tutorial used HelloJNI as the module name, and library name. I used "useaaacom".

推荐答案

来自

动态链接器根据其名称解析条目.本机方法名称由以下组件连接而成:

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

  • 前缀Java_
  • 完全限定的班级名称
  • 下划线(_)分隔符
  • 错误的方法名称
  • 对于重载的本机方法,两个下划线(__)后跟错误的参数签名
  • 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);
}

然后相应的C函数应为:

Then the corresponding C function should be:

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

如果Java方法名称中带有下划线:

If you have an underscore in the Java method name:

public native void A_Grill(int i);

那么C函数将是:

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

_1转义序列与A_Grill中的_相匹配.

The _1 escape sequence matches the _ in A_Grill.

这篇关于Java本机接口方法和模块名称的命名约定是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆