invoking String.equals() from FindClass("java/lang/Object")

Hi,

Lets say I have a jobject which I know is a java.lang.String object and sometimes

some other type of object. I want

to invoke jmethod for the "equals" method of java.lang.String when its

a String and the correct "equals" method when its not a String.

I can query env->GetObjectClass(), and then use env->GetMethodID(cls, "equals",

"(Ljava/lang/Object;)Z"), and then invoke the method but this is slow.

My question is, is the methodID for "equals" for the FindClass("java/lang/Object")

jclass good enough to invoke for an actual java.lang.String object, or do I have

to invoke using the jclass for FindClass("java/lang/String")?

Thanks,

Andy

[724 byte] By [p7ea] at [2007-10-3 1:21:14]
# 1

Yes it's "good enough". To get the method id only once you should use a global:

// Global variable

jmethodID equalsID = NULL;

...

// In your JNI function:

if (equalsID == NULL) // The following will be called only once

equalsID = env->GetMethodID(env->FindClass("java/lang/Object"), "equals", "(Ljava/lang/Object;)Z");

Regards

jfbrierea at 2007-7-14 18:18:28 > top of Java-index,Java HotSpot Virtual Machine,Specifications...