aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Is there a field class of type Class in Object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Is there a field class of type Class in Object" Watch "Is there a field class of type Class in Object" New topic
Author

Is there a field class of type Class in Object

Carlo Smits
Greenhorn

Joined: Jul 09, 2001
Posts: 22
If I say
System.out.println(Object.class),
I get as output the toString method of the Class class. Is there a hidden field class of type Class in Object? Because in JDK documentation I do not see any field in Object.
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
Hello Carlo
Object.class is a class literal. This is from JLS

15.8.2 Class Literals
A class literal is an expression consisting of the name of a class, interface, array, or primitive type followed by a `.' and the token class. The type of a class literal is Class. It evaluates to the Class object for the named type (or for void) as defined by the defining class loader of the class of the current instance.

Also the wrappers clases and java.lang.Void class have a TYPE field containing a Class object for the corresponding type:
Integer.TYPE <==> Integer.class
...
Void.TYPE <==> Void.class


SCJP2. Please Indent your code using UBB Code
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040
Good one, Carlo Jose.
Thanks.
- satya

Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
I am sorry I did a mistake in my previous answer.
The fields Integer.TYPE ... Void.TYPE holds references to int.class ... void.class objects.
Integer.class represents the Class object for java.lang.Integer class. Also Void.class is a class literal for java.lang.Void
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is there a field class of type Class in Object