Saturday, April 20, 2013

jni jnienv IsInstanceOf example c c++ java


IsInstanceOf


jboolean IsInstanceOf(JNIEnv *env, jobject obj,
jclass clazz);

Tests whether an object is an instance of a class.
LINKAGE:
Index 32 in the JNIEnv interface function table.
PARAMETERS of IsInstanceOf
env: the JNI interface pointer.

obj: a Java object.

clazz: a Java class object.

RETURNS:

Returns JNI_TRUE if obj can be cast to clazz; otherwise, returns JNI_FALSE. A NULL object can be cast to any class.
Example - IsInstanceOf

{
jclass objCls = env->FindClass ("com/mycompany/myapp/exception/MyException");
jclass objThrowable = env->FindClass ("java/lang/Throwable");
if(env->IsAssignableFrom(objCls, objThrowable) == JNI_TRUE) { /* TRUE! */ }
}
{
jclass objCls = env->FindClass ("com/mycompany/myapp/exception/MyException");
jclass objThrowable = env->FindClass ("java/lang/Throwable");
if(env->IsInstanceOf((jobject)exc, objCls) == JNI_TRUE) { /* FALSE */ }
if(env->IsInstanceOf((jobject)exc, objThrowable) == JNI_TRUE) { /* FALSE */ }
}