aspose file tools*
The moose likes Java in General and the fly likes .class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark ".class" Watch ".class" New topic
Author

.class

Sondra Colagrossi
Ranch Hand

Joined: Oct 30, 2002
Posts: 68
I inherited some code where the author is using a class member.
Something like Class myClass = System.class
I don't see this member in Object or System.
What's the deal?
James Chegwidden
Author
Ranch Hand

Joined: Oct 06, 2002
Posts: 201
Did you go to the Sun Documentation at java.sun.com? Check there.


Author and Instructor, my book
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Mmmm... it's true this is documented at java.sun.com, but this particular info is pretty hard to find unless you know about it already. It's not in the API anywhere (as far as I know), but rather the JLS. You're looking at what's called a class literal, and it's described here. Basically, "System.class" represents a Class object corresponding to the class "System". Despite its appearance, ".class" is not a member field of System, Object, or any other class - it's a special notation to refer directly to Class objects.
Note that you can even have things like "int.class", which refers to the Class object representing the primitive type int. So it's worth remembering that the class Class really can represent any type, not just classes, and they really should've named the class "Type" (or even "DataType") rather than "Class" to minimize confustion. Too late now though...
[ December 31, 2002: Message edited by: Jim Yingst ]

"I'm not back." - Bill Harding, Twister
Sondra Colagrossi
Ranch Hand

Joined: Oct 30, 2002
Posts: 68
Thank you and thanks to Sun for publishing the JLS on the web. I was hoping this was a deprecated relic of the 1.0 edition, but I see it's not.
I paid Ellis & Stroustrup a fortune for the C++ reference manual.
I was thinking of buying the JLS till I saw the Jini chick reference it. All I had seen was the first version at the book store.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: .class
 
Similar Threads
Why This Compiler Error?
Newbie: when to use form and request params
static modifiers
Member class can have static variables??
Can we modify a private variable outside a class?