Java Reference
In-Depth Information
3 private static float a - static - float;
4 Signature: F
5 private int some - int;
6 Signature: I
7 private int[] array;
8 Signature: [I
9 private int[][] array2d;
10 Signature: [[I
11 private java.lang.String some - string;
12 Signature: Ljava/lang/String;
13 private javatech.jni22.MyCustomObject my - custom;
14 Signature: Ljavatech/jni22/MyCustomObject;
15 public javatech.jni22.JNIDemo();
16
Signature: ()V
17 }
where we have added line numbers to aid the discussion. Lines 3, 5, 7, etc. echo
the original lines declaring the fields in the source file. Lines 4, 6, 8, etc. give the
type signatures for each type. This pattern continues for each field until we get
to lines 15 and 16, which give the signature of the class constructor. We discuss
more about method signatures shortly.
22.8.2 The jclass
We used a variable called cls above when calling GetFieldID() .Toobtain
a field ID for a field in a particular class, the JNI subsystem obviously needs to
have information about that class. That information is embodied in the jclass
type. For static native methods called from Java, recall that the native function
signature includes a jclass parameter. Therefore, to access fields within the
class that declares the native method, the cls variable is already available.
Suppose our JNIDemo class used in the examples above declared and called
a static native method doStatic() and a non-static method doNonStatic()
as shown here:
package javatech.jni22;
public class JNIDemo
{
// native methods
public static native void doStatic ();
public native void doNonStatic ();
// a class variable
private static float a - static - float;
// instance variables
private int some - int;
private int[] array;
Search WWH ::




Custom Search