Determine the signature of a method
Before calling a Java object's method from JNI, we need its signature. For example, the methodlong myMethod (int n, String s, int[] arr);is seen from JNI with the signature
(ILJAVA/LANG/STRING;[I)JThere are two parts to the signature. The first part is enclosed within the parentheses and represents the method's arguments. The second portion follows the closing parenthesis and represents the return type. The mapping between the Java type and C type is
Type Chararacter boolean Z byte B char C double D float F int I long J object L short S void V array [ Note that to specify an object, the "L" is followed by the object's class name and ends with a semi-colon, ';' .
The javap utility (included with the JDK) is very useful to show the signature to be used in JNI.
public class java.awt.Label extends java.awt.Component { public static final int LEFT; /* I */ public static final int CENTER; /* I */ public static final int RIGHT; /* I */ java.lang.String text; /* Ljava/lang/String; */ int alignment; /* I */ static {}; /* ()V */ public java.awt.Label(); /* ()V */ public java.awt.Label(java.lang.String); /* (Ljava/lang/String;)V */ public java.awt.Label(java.lang.String,int); /* (Ljava/lang/String;I)V */ public void addNotify(); /* ()V */ java.lang.String constructComponentName(); /* ()Ljava/lang/String; */ public int getAlignment(); /* ()I */ public java.lang.String getText(); /* ()Ljava/lang/String; */ protected java.lang.String paramString(); /* ()Ljava/lang/String; */ public synchronized void setAlignment(int); /* (I)V */ public void setText(java.lang.String); /* (Ljava/lang/String;)V */
页:
[1]