2. JNI 类型和数据结构

来源:互联网 发布:iphone透明屏幕软件 编辑:程序博客网 时间:2024/05/16 02:28

来自:JNI Types And Data Structures

1. Primitive Types

Primitive Types and Native Equivalents:

Java Type Native Type Description boolean jboolean unsigned 8 bits byte jbyte signed 8 bits char jchar unsigned 16 bits short jshort signed 16 bits int jint signed 32 bits long jlong signed 64 bits float jfloat 32 bits double jdouble 64 bits void void not applicable

2. Reference Types

JNI reference hierarchy:

  • jobject
    • jclass (java.lang.Class objects)
    • jstring (java.lang.String objects)
    • jthrowable (java.lang.Throwable objects)
    • jarray (arrays)
      jobjectArray (object arrays)
      jbooleanArray (boolean arrays)
      jbyteArray (byte arrays)
      jcharArray (char arrays)
      jshortArray (short arrays)
      jintArray (int arrays)
      jlongArray (long arrays)
      jfloatArray (float arrays)
      jdoubleArray (double arrays)

3. Field and Method IDs

Method and field IDs are regular C pointer types:

struct _jfieldID;              /* opaque structure */typedef struct _jfieldID *jfieldID;   /* field IDs */struct _jmethodID;              /* opaque structure */typedef struct _jmethodID *jmethodID; /* method IDs */

4. The Value Type

The jvalue union type is used as the element type in argument arrays. Declared as follows:

typedef union jvalue {    jboolean z;    jbyte    b;    jchar    c;    jshort   s;    jint     i;    jlong    j;    jfloat   f;    jdouble  d;    jobject  l;} jvalue;

5. Type Signatures

The JNI uses the Java VM’s representation of type signatures.

Java VM 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

Eg:
Java method

long f (int n, String s, int[] arr);

The following type signatures:

//整体结构:(参数)返回值//参数:I - int n;Ljava/lang/String - String s;[I - int[] arr//返回值:J - long(ILjava/lang/String;[I)J

6. Modified UTF-8 Strings

参考地址:Modified UTF-8 Strings

原创粉丝点击