/**
* 全局引用
* 可以全局缓存
*/
extern "C"
JNIEXPORT jstring JNICALL
Java_com_jdqm_ndktutorials_jni_JNIReference_cacheWithGlobalReference(JNIEnv *env, jobject thiz) {
static jclass stringClass = nullptr;
if (stringClass == nullptr) {
jclass cls = env->FindClass("java/lang/String");
stringClass = static_cast<jclass>(env->NewGlobalRef(cls));
env->DeleteLocalRef(cls);
} else {
LOGD("USER CACHED");
}
jmethodID mid = env->GetMethodID(stringClass, "<init>", "(Ljava/lang/String;)V");
jstring str = env->NewStringUTF("string");
return static_cast<jstring>(env->NewObject(stringClass, mid, str));
}