Getting a reference to a super class.
Suppose I have:
* a class named Base which contains a function named foo().
* a class named Derived which extends Base that also has a function foo().
I'd like to call Base::foo() using JNI (this is me playing around getting to know JNI; I know this isn't terribly useful).
In Derived, I defined:
publicnativevoid nativeMethod();
The first step is to get a class reference for Base.So I do this:
JNIEXPORTvoid JNICALL
Java_Derived_nativeMethod(JNIEnv *env, jobject obj)
{
jclass cls = env->GetObjectClass(obj);
jmethodID mid = env->GetMethodID(cls,"foo","()V");
if ( mid == NULL )return;
env->CallVoidMethod(cls, mid);
}
But there's already a problem. Since nativeMethod() is called from within Derived::main(), the jobject that's passed to nativeMethod() is an instance of a Derived object, not the Base object.So Derived::foo() will be called, not Base::foo().
How do I get a reference to the super class in order to run Base::foo()?
Thanks!

