This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

.class

 
Sondra Colagrossi
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 201
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you go to the Sun Documentation at java.sun.com? Check there.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Sondra Colagrossi
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic