This article was reproduced in: http://blog.csdn.net/qinjuning
There are two types of data in Java: Basic types and reference types, which everyone knows.
Similar data types exist in the JNI world, which, compared to Java, is more rigorous in scope, as follows:
1, primitive types----basic data types, such as: int, float, char and other basic types
2, reference types----reference type, such as: Class, instance, array.
It is important to note that the array ------Whether it is an object array or an array of primitive types, is present as reference types.
1, primitive types (basic data type) map, see the following table:
These basic data types are available directly in the native layer.
2.reference types (reference data type) map see the table below
Java type Native type description
Note :
1. reference data types are not directly available and need to be converted according to the JNI function to use the
2, multidimensional arrays (including two-dimensional arrays) are reference types and need to access their values using the Jobjectarray type;
For example, a two-dimensional integer array is an array that points to an array that is declared using the following method:
// gets the class reference of a one-dimensional array, that is, the Jintarray type Jclass Intarrayclass = Env->findclass ("[I"); // constructs an array of objects that point to a one-dimensional array of Jintarray classes with an initial size of dimion Jobjectarray Obejctintarray = env->newobjectarray (dimion, Intarrayclass, NULL); ... // Specific Operation
In addition, one of the inheritance relationships for reference types is that we can convert types that have parent-child relationships:
Class Descriptor
The class descriptor is the full name of the class (package name + class name), which will be the original. The delimiter is replaced by the/separator character.
For example, the class descriptor of the Java.lang.String class in Java code is java/lang/string
In fact, in practice, I found that it is possible to replace the domain descriptor directly with that type, and it can be successful.
Example: Jclass intarrcls = Env->findclass ("java/lang/string")
Equivalent to Jclass intarrcls = Env->findclass ("ljava/lang/string;")
The descriptor for the array type is: [+ field descriptor of its type (description below)
For example:
int [] whose descriptor is [I
float [] whose descriptor is [F
String [] whose descriptor is [ljava/lang/string;
Domain Descriptor
1. The descriptor of the basic type is already defined, as shown in the following table:
2. Descriptor of reference type
The general reference type is L + the type class descriptor +; (Note that the semicolon here ";" is only part of the JNI, not our Chinese segmentation, the same below)
For example, the field descriptor for String type is ljava/lang/string;
For an array, it is: [+ the domain descriptor of its type +;
Int[] whose descriptor is [I
Float[] whose descriptor is [F
String[] Its descriptor is [ljava/lang/string;
The field descriptor for the object[] type is [Ljava/lang/object;
A multidimensional array is n [+ the domain descriptor of the type, and N represents a few-dimensional array. For example:
int [] [] whose descriptor is [[I
Float[] [] whose descriptor is [[F]
Method descriptor
The field descriptor of the parameter type is placed in parentheses in the order of declaration followed by the field descriptor of the return value type, as follows: (overlay of the parameter's field descriptor) returns
The type descriptor. For, there is no return value, denoted by V (representing void type). Examples are as follows:
Java Layer method JNI function signature
String test () ljava/lang/string;
int f (int i, Object object) (Iljava/lang/object;) I
void set (byte[] bytes) ([B) V
In programming, if the use of Javah tools, these do not require us to manually write the corresponding type conversion, if not with the Javah tool, you can only manually
The type conversion was made.
The next article will be a concrete real station to grasp the specific jni.
Analyze a series of blogs developed using the Android NDK, and feel pretty good:
"Android NDK Development (3) ———— A detailed description of the JNI data types"
Reproduced Two----of JNI learning accumulation data type mapping, description of domain descriptor