Array Name Encodings
Home ] Up ] The Class Class ] Examining a Class ] [ Array Name Encodings ] Creating a Class Instance ] The Reflection Classes ]

 

 

Note the strange output for arrays.  In the case of an array, the toString() method (and the getName() method) for Class returns a name like:

[Ljava.lang.Double;

Where the [ means "array of" and the remaining character(s) are chosen from the following table (see the Java Language Specification), with the specified meaning.

B byte
C char
D double
F float
I int
J long
L class or interface
S short
Z boolean

For example, the following piece of code:

(new int[3][4][5][6][7][8][9]).getClass().getName()

returns:

[[[[[[[I

This strange encoding is used in a number of places in Java, notably in Reflection and also in JNI (Java Native Interface) when interfacing with code written in other languages (notably C and C++).

 

The page was last updated February 19, 2008