Java Reference
In-Depth Information
Table 22.1
JNI Type Signatures.
Java type
Signature
boolean
Z
byte
B
char
C
short
S
int
I
long
J
float
F
double
D
type
[]
[
type
Class
L
fully-qualified-class;
replacing dots, and ends with a semicolon. So the
String
field's type sig-
nature is
“
Ljava/lang/String;
„
. The type signature for a custom object
is similar. It just specifies the custom path to the object instead of a path
inside the
java.lang
package. So the type signature of
MyCustomObject
is
“
Ljavatech/jni22/MyCustomObject;
„
.Anarray of object types is
merely prefixed with a left square bracket, just like arrays of primitives.
The complete mapping of Java types to JNI type signatures is given in
Table 22.1. Notice that the type signature does not differ for static and non-static
fields. That difference is handled by using either the
GetStaticFieldID()
or
GetFieldID()
function, respectively. With this table and the rules given above,
one can generate the type signature of any field in any class. However, rather than
manually using the table and rules, it is often easier to use the
javap
tool to dis-
play the signatures automatically. This tool operates on a compiled class file, and
the
-s
option is used to generate type signatures. By default,
javap
generates
only the signatures for the default, protected, and public access scope classes and
fields. Use the
-private
option to show all classes and fields. With our
java-
tech.jni22.JNIDemo
class
described
above
compiled
into
build/
classes
,welaunch
javap
as follows:
javap -s -private -classpath build/classes
javatech.jni22.JNIDemo
where we fully specify the class name (
javatech.jni22.JNIDemo
)onthe
command line and also set the classpath to point to the
build/classes
direc-
tory. The output from
javap
is
1 Compiled from
"
JNIDemo.java
"
2 public class javatech.jni22.JNIDemo extends
java.lang.Object
{
Search WWH ::
Custom Search