Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Class of array?

 
Kousik Majumder
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

Can somebody tell me what are the class of all primitive types?
Except String.....
e.g-> int obj[] = new int[2];

which class's object is obj?

Thanks,
Kousik
 
Campbell Ritchie
Sheriff
Pie
Posts: 49447
64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java Language Specification �10.8. There is a list of what the 8 letters are, but I can't seem to find it. I think they are B (byte) C D F I L S and Z (boolean). They are mostly the initials of the primitive types, but in upper case.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49447
64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have found a list of the letters in a book (Lemay and Cadenhead, teach yourself Java2 in 21 days, SAMS, 2/e, page 479).
B byte
C char
D double
F float
I int
J long
L object
S short
Z boolean
As you have seen from the link I gave earlier, there is an associated [ and [L is followed by the name of the class
[ September 09, 2008: Message edited by: Campbell Ritchie ]
 
Rob Spoor
Sheriff
Pie
Posts: 20552
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Kousik Majumder:
e.g-> int obj[] = new int[2];

which class's object is obj?

The simple answer: int[].class

You see it right: you can use .class with arrays as well. You can even use it with the primitive types: int.class will return the class that represents int in reflection. You can also find that one through Integer.TYPE.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic