Search code examples
javac++java-native-interface

Comparing JNI object references


I call a Java method from c++ via JNI. The Java method returns an enum STATUS. I already have the jobjects representing the enums in my c++ code like here: https://stackoverflow.com/a/17441151/3352197

jclass clSTATUS    = env->FindClass("MyClass$STATUS");
jfieldID fidONE    = env->GetStaticFieldID(clSTATUS , "ONE", "LMyClass$STATUS;");
jobject STATUS_ONE = env->GetStaticObjectField(clSTATUS, fidONE);

So, the call

jobject o = env->CallObjectMethod(jTestobject, test);

returns a jobject representing an enum STATUS, specially ONE. So, how do I know which enum it has returned? I tried to compare it to STATUS_ONE, but they do not match.


Solution

  • Found it by myself, after Samhain pointed out my possible mistake. You just have to compare the objects correctly:

    env->IsSameObject(o, STATUS_ONE);
    

    Thank you!