【发布时间】:2020-02-18 18:41:35
【问题描述】:
如何在 JNI 上使用 Kotlin 可空类型,例如 'Long?'、'String?' 等强>? 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
【问题讨论】:
标签: kotlin java-native-interface nullable