File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

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?

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

Joined: Jul 08, 2003
Posts: 24199

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
Ranch Hand

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

I agree. Here's the link:
subject: What is the class for array type reference?
It's not a secret anymore!