Search code examples
javac++qtjava-native-interfacesignature

What's "Method Signature" parameter when calling a Java method using JNI?


I want to call an Android Java method using JNI in Qt. There is a weird "Method Signature" parameter that I cannot understand. What's this and how should I set it?

In examples it's something like (II)I or (I)I. What does it mean?

For example:

jint max = QAndroidJniObject::callStaticMethod<jint>("java/lang/Math", "max", "(II)I", a, b);

Solution

  • It is all explained in the docs. http://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/types.html

    Type Signature   Java Type
    Z                boolean
    B                byte
    C                char
    S                short
    I                int
    J                long
    F                float
    D                double
    L fully-qualified-class ;   fully-qualified-class
    [ type           type[]
    ( arg-types ) ret-type method type
    

    Your (II)I is a method taking two integers as arguments and returning an int. E.g. int m(int i, int j).

    A method void print(String message) would be (Ljava/lang/String;)