如何知道Jobject所属的jclass(JNI) [英] How to know the jclass to which a jobject belongs (JNI)
问题描述
我需要从我的JNI代码中调用相同的本机C方法.此方法接收通用的 jobject
对象,但是其行为因对象本身的类型而异.
我有两个 jclass
对象,分别名为activityCls和fragmentCls(它们分别映射Java中的Activity类和Fragment类).为了知道给定的 jobject
对象是activityCls还是fragmentCls,该怎么办?
如何使用 IsInstanceOf
?
IsInstanceOf
jboolean IsInstanceOf(JNIEnv * env,jobject obj,jclass clazz);
测试对象是否是类的实例.
JNI文档 >
I need to call the same native C method from my JNI code. This method receives a generic jobject
object, but its behavior is different depending on the type of the object itself.
I have two jclass
objects, named activityCls and fragmentCls (which respectively map an Activity class and a Fragment class in Java). What can I do in order to know if the given jobject
object is of kind activityCls or fragmentCls?
How about using IsInstanceOf
?
IsInstanceOf
jboolean IsInstanceOf(JNIEnv *env, jobject obj, jclass clazz);
Tests whether an object is an instance of a class.
这篇关于如何知道Jobject所属的jclass(JNI)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!