Kotlin 可空 JNI 类型

Kotlin Nullable JNI Type

如何使用 Kotlin 可空类型,例如 'Long?'、'String?' 等等 JNI? JNI 类型签名代表以下信息:

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

但是我如何使用 JNI 中的可空 'var value:Long?'?

Kotlin 代码

class KtClass
{
    var value:Long? = null
}

JNI

jclass ktclass = env->FindClass("package/KtClass");
jmethodID ctorktID = env->GetMethodID(ktclass, "<init>", "()V");
env->NewObject(ktclass, ctorktID);

//J - mean Kotlin Long, but it not nullable 'Long?'
jfieldID valueID = env->GetFieldID(ktclass, "value", "J");
env->SetLongField(ktclass, valueID, NULL); //Error

Long? 在 JVM 上变为 java.lang.Long,所以使用

env->GetFieldID(ktclass, "value", "Ljava/lang/Long;")