如何处理 Kotlin可为空的类型,例如' Long? ','字符串? 上的'等。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
但是如何使用可为空的 var值:长? '来自JNI?
Kotlin 密码
class KtClass
{
var value:Long? = null
}
杰尼
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;")
关于kotlin - Kotlin可空JNI类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60278610/