Specification of CallStatic<Type>Method family says:
"The method ID must be derived from clazz, not from one of its superclasses."
But the functions allow to pass not only the superclass declaring the type, but any arbitrary type.
Example:
============================
public class CallStaticTest {
private static native void nativeMethod();
public static void m() {
System.out.println("Static method m is called!");
}
public static void main(String[] args) throws NoSuchMethodException {
System.loadLibrary("CallStaticTest");
nativeMethod();
}
}
============================
#include "jni.h"
JNIEXPORT void JNICALL Java_CallStaticTest_nativeMethod
(JNIEnv * env, jclass clazz, jobject method)
{
jmethodID methodID = (*env)->GetStaticMethodID(env, clazz, "m", "()V");
jclass stringClass = (*env)->FindClass(env, "java/lang/String");
(*env)->CallStaticVoidMethod(env, stringClass, methodID);
}
============================
$ javac CallStaticTest.java -d classes
$ gcc -m64 -shared -o CallStaticTest.dll -I"$jdk\include" -I'$jdk\include\win32' CallStaticTest.c
$ java -cp classes CallStaticTest
Static method m is called!
============================