2. JNI 类型和数据结构

4 篇文章 0 订阅

来自:JNI Types And Data Structures

1. Primitive Types

Primitive Types and Native Equivalents:

Java TypeNative TypeDescription
booleanjbooleanunsigned 8 bits
bytejbytesigned 8 bits
charjcharunsigned 16 bits
shortjshortsigned 16 bits
intjintsigned 32 bits
longjlongsigned 64 bits
floatjfloat32 bits
doublejdouble64 bits
voidvoidnot 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 SignatureJava Type
Zboolean
Bbyte
Cchar
Sshort
Iint
Jlong
Ffloat
Ddouble
L fully-qualified-class ;fully-qualified-class
[ typetype[]
( arg-types ) ret-typemethod 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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值