JNI

来源:互联网 发布:log4j.xml 配置 sql 编辑:程序博客网 时间:2024/06/08 10:38

--------------------类型映射(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 类型本地类型描述booleanjbooleanC/C++8位整型bytejbyteC/C++带符号的8位整型charjcharC/C++无符号的16位整型shortjshortC/C++带符号的16位整型intjintC/C++带符号的32位整型longjlongC/C++带符号的64位整型floatjfloatC/C++32位浮点型doublejdoubleC/C++64位浮点型Objectjobject任何Java对象,或者没有对应Java类型的对象ClassjclassClass对象Stringjstring字符串对象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)

http://docs.oracle.com/javase/6/docs/technotes/guides/jni/spec/types.html
Type SignatureJava TypeZbooleanBbyteCcharSshortIintJlongFfloatDdoubleL fully-qualified-class ;fully-qualified-class[ typetype[]( arg-types ) ret-typemethod 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


--------------------资料推荐
Advanced Programming for the Java 2 Platform,http://java.sun.com/developer/onlineTraining/Programming/JDCBook/jni.html

原创粉丝点击