This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Java in General and the fly likes What is meant by .class ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "What is meant by .class ?" Watch "What is meant by .class ?" New topic
Author

What is meant by .class ?

Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

In methods that require a parameter of type java.lang.class, I've seen the following syntax...
So is saying:
java.lang.String.class
kind of like a shortcut for saying:
Class.forName("java.lang.String")

?
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Yes. It's called a class literal. Looks like a static field or something but isn't (as you can determine via reflection if so inclined). The compiler interprets it as a direct reference to a particular Class object, the same way "foo" is a direct reference to a String object with contents f-o-o, without any visible constructor or method call. Interestingly, you even have Class objects for
int.class
void.class
These are useful for things like specifying the return type of a method when using reflection (which wants to use Class objects for everything, even things that aren't anything.)
I'm mildly disappointed to see there's no null.class, even though I can't (yet) imagine what we could possibly use it for. I'll think of something...
[ May 20, 2003: Message edited by: Jim Yingst ]

"I'm not back." - Bill Harding, Twister
Jasper Vader
Ranch Hand

Joined: Jun 10, 2002
Posts: 57
what is reflection?


giddee up
John Lee
Ranch Hand

Joined: Aug 05, 2001
Posts: 2545
Trail: The Reflection API
Using Java Reflection
Take an in-depth look at the Java Reflection API
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What is meant by .class ?