现在的位置: 首页 > 综合 > 正文

JNI

2013年10月18日 ⁄ 综合 ⁄ 共 2093字 ⁄ 字号 评论关闭

--------------------类型映射(the mapping of types between Java and native code)

英文版:

http://docs.oracle.com/javase/6/docs/technotes/guides/jni/spec/types.html

or

docs/technotes/guides/jni/spec/types.html

中文版:

Java 类型 本地类型 描述
boolean jboolean C/C++8位整型
byte jbyte C/C++带符号的8位整型
char jchar C/C++无符号的16位整型
short jshort C/C++带符号的16位整型
int jint C/C++带符号的32位整型
long jlong C/C++带符号的64位整型
float jfloat C/C++32位浮点型
double jdouble C/C++64位浮点型
Object jobject 任何Java对象,或者没有对应Java类型的对象
Class jclass Class对象
String jstring 字符串对象
Object[] jobjectArray 任何对象的数组
boolean[] jbooleanArray 布尔型数组
byte[] jbyteArray 比特型数组
char[] jcharArray 字符型数组
short[] jshortArray 短整型数组
int[] jintArray 整型数组
long[] jlongArray 长整型数组
float[] jfloatArray 浮点型数组
double[] jdoubleArray 双浮点型数组

引用至:http://www.blogjava.net/china-qd/archive/2006/04/29/44002.html

The following definition is provided for convenience.

#define JNI_FALSE  0
#define JNI_TRUE   1

The jsize integer type is used to describe cardinal indices and sizes:

typedef jint jsize;

In C, all other JNI reference types are defined to be the same as jobject. For example:

typedef jobject jclass;

In C++, JNI introduces a set of dummy classes to enforce the subtyping relationship. For example:

class _jobject {};
class _jclass : public _jobject {};
...
typedef _jobject *jobject;
typedef _jclass *jclass;

--------------------类型签名(Type Signatures)

Type Signature Java Type
Z boolean
B byte
C char
S short
I int
J long
F float
D double
L fully-qualified-class ; fully-qualified-class
[ type type[]
( arg-types ) ret-type method type
For example, the Java method:

long f (int n, String s, int[] arr); 
has the following type signature:
(ILjava/lang/String;[I)J 

说明:

1." fully-qualified-class" :完全限定类,如java.lang.String

2." Ljava/lang/String;":java/lang/String

3. "[I ":int[]

签名:

签名是一种用参数个数和类型区分同名方法的手段,即解决方法重载问题。
其中要特别注意的是:
1. 类描述符开头的'L'与结尾的';'必须要有
2. 数组描述符,开头的'['必须有
3. 方法描述符规则: "(各参数描述符)返回值描述符",其中参数描述符间没有任何分隔符号
描述符很重要,请烂熟于心. 写JNI,对于错误的签名一定要特别敏感,此时编译器帮不上忙,执行make前仔细检查你的代码。

【参考资料】

jni详解,http://wenku.baidu.com/view/a06ff70d6c85ec3a87c2c55a.html

http://www.blogjava.net/china-qd/archive/2006/04/29/44002.html

--------------------资料推荐

抱歉!评论已关闭.