Search code examples
javajava-native-interface

JNI signature of non-packaged objects


according to the doc:

The name argument is a fully-qualified class name or an array type signature . For example, the fully-qualified class name for the java.lang.String class is: "java/lang/String"

My question is a Java newbie question, what's the signature of a class which isn't packaged?


Solution

  • If YourClass is a class in default package then the fully qualified name is simply YourClass.

    If the Java method is

    public void method(YourClass x);
    

    then you can search the method via:

    jmethodID m = (*env)->GetMethodID(env, javaclass, "method", "(LYourClass;)V");
    

    The tool javah may generate an *.h file where you can see the method signature.

    The fully qualified name can be easily printed from java

    System.out.println(instanceOfYourClass.getClass().getName());