Since: http://book.51cto.com/art/201305/395888.htm has read a lot of articles about JNI, or the author of this article to talk about the best, the most point.
This book should be well written.
2.4.3 JNI method signature rules
With the ing between data types, JNI can correctly identify and convert Java types. So how does JNI identify Java?
JAVA supports method overloading. A method cannot be uniquely identified by function name alone. Therefore, JNI provides a set of signature rules that use a string to uniquely identify a method. The rules are as follows:
(Parameter 1 type signature parameter 2 type signature ...... Parameter n type signature) return value type signature
There is no space between the above signature strings.
Type Signatures have some rules, as shown in Table 2-3.
Table 2-3 JNI signature rules
(Continued)
Note that the class signature rules are composed of three parts: "l + fully qualified class name +;". The fully qualified class names are separated by "/" instead of ". "or" _ "are separated.
For example, the Java method:
- long fun (int n, String str, int[] arr);
The method signature:
- (ILjava/lang/String;[I)J
The content in the brackets is divided into three parts with no spaces, namely, "I", "ljava/lang/string;", and "[I ", int, string, and INT []. The signature of the return value type is displayed outside the brackets, and J indicates the long type.
Return to the log system example. The second element in the jninativemethod struct is the method signature information. The Code is as follows:
- static JNINativeMethod gMethods[] = {
- { "isLoggable", "(Ljava/lang/String;I)Z",(void*)
- android_util_Log_isLoggable },
- { "println_native","(IILjava/lang/String;Ljava/lang/String;)I",(void*)
-
- android_util_Log_println_native },
- };
The isloggable function has two parameters: string type and INT type. The return value is boolean type.
So far, we can correctly identify the type information and function information. How can I operate objects and access their member variables and methods? Continue in the next section.