Friday, April 19, 2013

jni jnienv IsAssignableFrom example c c++ java


IsAssignableFrom


jboolean IsAssignableFrom(JNIEnv *env, jclass clazz1, jclass clazz2);

Determines whether an object of clazz1 can be safely cast to clazz2.
LINKAGE:
Index 11 in the JNIEnv interface function table.
PARAMETERS (of IsAssignableFrom)

env: the JNI interface pointer.

clazz1: the first class argument.

clazz2: the second class argument.

RETURNS of IsAssignableFrom

Returns JNI_TRUE if either of the following is true:

  • The first and second class arguments refer to the same Java class.

  • The first class is a subclass of the second class.

  • The first class has the second class as one of its interfaces.


Example - IsAssignableFrom

{

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