GeeCON Prague 2014*
The moose likes Beginning Java and the fly likes What is the class for array type reference? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "What is the class for array type reference?" Watch "What is the class for array type reference?" New topic
Author

What is the class for array type reference?

Chandra Bairi
Ranch Hand

Joined: Sep 12, 2003
Posts: 152
class TestInt {
TestInt a[];
public static void main(String[] a) {
System.out.println("Class name :"+a.getClass()+ " got it");
}
}
O/p is class [Ljava.lang.String;
What does that mean?


Thanks,
Shekar
Tom Blough
Ranch Hand

Joined: Jul 31, 2003
Posts: 263
It appears the the "[L" denotes an array. I wonder if it's a typo in the library and should be "[]".


Tom Blough<br /> <blockquote><font size="1" face="Verdana, Arial">quote:</font><hr>Cum catapultae proscriptae erunt tum soli proscripti catapultas habebunt.<hr></blockquote>
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Java class files use a specific "type code" notation to describe the type of fields and the signatures of methods. A synopsis:
There's a single letter that stands for each primitive type:
I is int, F is float, D is double, J is long, V is void, etc.
A class type is denoted by the letter "L", followed by the name of the class using "/" as a separator, followed by a ";". So "Ljava/lang/String;"
An array is denoted by a prefix "[", so that an array of String is "[java/lang/String;" . A 2D array of int would be "[[I".
A method signature is a set of parentheses containing the types of the arguments separated by commas, followed by the return type of the method; so the signature of main is "([Ljava/lang/String ;) V" .
Now, when you call getClass().getName() on an array class, Java converts the slashes to periods, but otherwise passes you the same type descriptor that would be used in the class file.
This page contains all the details.
[ October 23, 2003: Message edited by: Ernest Friedman-Hill ]

[Jess in Action][AskingGoodQuestions]
Donald R. Cossitt
buckaroo
Ranch Hand

Joined: Jan 31, 2003
Posts: 401
See Retrieving Component Types at java.sun.com.
Also see "ALLOWED_CLASSNAMES" under "Field Detail" and "getClassName" under "Method Detail" of Class Open Type
HTH


doco
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What is the class for array type reference?