[JNI] abbreviation of Java type in JNI

Source: Internet
Author: User
In JNI, when we use getfieldid/getstaticfieldid or getmethodid/getstaticmethodid and define jninativemethod, We need to indicate the type of the member variable, or the type of the input parameter or returned by the function. JNI abbreviated the field type, or the type of input parameter or return value of the function as char.

For member variables, you can simply use the abbreviation of Java type to indicate the type of member variables. For example, "I" indicates that the member variable is of the int type. "Ljava/lang/string;" indicates that the member variable is of the string type. Example 1: Jfieldid STR = (ENV)-> getfieldid (objectclass, "name", "ljava/lang/string ;"); Jfieldid ival = (ENV)-> getfieldid (objectclass, "serial", "I "); For a member function, "(*) +" is used to indicate the input parameters of the function, the type of the input parameter, and the type of the return value. The character in "()" indicates the input parameter, and the subsequent character indicates the return value. For example: "() V" indicates void func (); "(Ii) V" indicates void func (INT, INT ); "(Ljava/lang/string;) I". Int func (string, string) Example 2:

Static jninativemethod gpowermanagerservicemethods [] = { /* Name, signature, funcptr */ {"Nativeinit", "() V ", (Void *) android_server_powermanagerservice_nativeinit }, {"Nativesetpowerstate", "(zz) V ", (Void *) android_server_powermanagerservice_nativesetpowerstate }, {"Nativestartsurfaceflingeranimation", "(I) V ", (Void *) android_server_powermanagerservice_nativestartsurfaceflingeranimation }, };

For abbreviated type, see the following table.Table


Java
Type

Symbol

Boolean

Z

Byte

B

Char

C

Short

S

Int

I

Long

L

Float

F

Double

D

Void

V

Objects object

It starts with "L" and ends with ";". It is a package and class name separated by "/" in the middle.

For example: ljava/lang/string;

For Nested classes, $ is used to represent nesting.

For example, "(ljava/lang/string; landroid/OS/fileutils $ filestatus;) z"

In addition, the abbreviation of the array type can be expressed in the abbreviated form of "[" and the corresponding type shown in table, For example, [I indicates int []; [l/Java/lang/objects; indicates objects. The identifier of the reference type (except the basic type array) is ";"
Related Article

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.