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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "The .class property" Watch "The .class property" New topic
Author

The .class property

Dmitriy Pavlyuk
Ranch Hand

Joined: Mar 25, 2001
Posts: 33
Explain me please, where from the .class property appears in any Object descendant. It's not in Object!
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
I am going to guess that you are asking about reflection.
The JVM creates the Class object for each class.
From the API for Class:

Class has no public constructor. Instead Class objects are constructed automatically by the Java Virtual Machine as classes are loaded and by calls to the defineClass method in the class loader.


"JavaRanch, where the deer and the Certified play" - David O'Meara
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4442
    
    5

Or perhaps you are referring to Class Literals, which are evaluated at compile time and evaluate to the Class object of the named type. Refer to JLS �15.8.2 Sample usage below:

[This message has been edited by JUNILU LACAR (edited June 28, 2001).]


Junilu - [How to Ask Questions] [How to Answer Questions]
rani bedi
Ranch Hand

Joined: Feb 06, 2001
Posts: 358
Whats the use of the Class Literal?


Cheers,<br />Rani<br />SCJP, SCWCD, SCBCD
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Well, it allows you to refer to a particular Class object directly, without having to create an instance of the class first. If I want a StringBuffer Class object, it's more efficient to say "StringBuffer.class" than "new StringBuffer().getClass()".


"I'm not back." - Bill Harding, Twister
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: The .class property
 
Similar Threads
Static keyword Doubt
JDK violating Encapsulation ?
some help
Static overridden method
what is the definition of "object" and "class"?