Search code examples
javajava-native-interface

What's the difference between xxx(JNIEnv *env, jobject thisObj) and xxx(JNIEnv *env, jclass cls)?


I saw some jni signatures as the following:

// jni
// WAY-1
JNIEXPORT void JNICALL Java_com_test_Test_testMethod(JNIEnv *env,  jobject thisObj);

// WAY-2
JNIEXPORT void JNICALL Java_com_test_Test_testMethod(JNIEnv *env, jclass cls);

And the java code maybe like this:

// java
package com.test;

public class Test {
    public native void testMethod(); 
}

What's the difference between WAY-1 and WAY-2 ?


Solution

  • The second call signature (WAY-2) is used for static methods, which do not have an object instance.