A good article on JNI method signature rules

Source: Internet
Author: User

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:

 
 
  1. long fun (int n, String str, int[] arr); 

The method signature:

 
 
  1. (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:

 
 
  1. static JNINativeMethod gMethods[] = {  
  2.    { "isLoggable", "(Ljava/lang/String;I)Z",(void*)  
  3.   android_util_Log_isLoggable },  
  4.    { "println_native","(IILjava/lang/String;Ljava/lang/String;)I",(void*)  
  5.  
  6.   android_util_Log_println_native },  
  7. };  

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.