wood burning stoves 2.0*
The moose likes Java in General and the fly likes what exactly meant by ANYCLASS.class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "what exactly meant by ANYCLASS.class" Watch "what exactly meant by ANYCLASS.class" New topic
Author

what exactly meant by ANYCLASS.class

Rajesh Tarte
Ranch Hand

Joined: Nov 02, 2006
Posts: 33

Hi
currently i am reading a book on java reflection

and noticed few things

consider Class A
Then there will be one class that is instance of Class such as A.class that represents the class A
at runtime
Class is instance of Object and Object will be instance of Class and A will have Object and Class as superclass

but what i noticed
is Object.class isInstance Class.class is true
and CLass.class isInstance Object.class is true

we generally refers static field by class name
then i do not found class in Class further as per java's naming convention we can not use keywords for varible name
so i dint get what is eactly .class(i am not talking about .class file ) and where did it come from

I am not able to procced

waiting for experts comment

Krishna


SCJP 1.5 | SCWCD 5.0 |SCBCD
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19653
    
  18

Not user interface related. Moving to a better forum.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Rajesh Tarte
Ranch Hand

Joined: Nov 02, 2006
Posts: 33

how to move it?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19653
    
  18

Only bartenders and sheriffs can move threads. I already did it.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18531
    
  40

consider Class A
Then there will be one class that is instance of Class such as A.class that represents the class A
at runtime
Class is instance of Object and Object will be instance of Class and A will have Object and Class as superclass


The java.lang.Class class is a class used to report information about Java classes. This is why from any class, you can get an instance of such a class. With this instance, you can figure out what fields it has, what method it has, contructors, etc....


but what i noticed
is Object.class isInstance Class.class is true
and CLass.class isInstance Object.class is true


I am assuming that you mean the isInstance() method of the java.lang.Class class. The purpose of this method is to report if two instances are instances of the same class. This means that String("henry") isInstance() String("wong") is also true, since they are both String instances.

So, all your test proves is that ANYCLASS.class refers to an instance that is of the same class.

we generally refers static field by class name
then i do not found class in Class further as per java's naming convention we can not use keywords for varible name
so i dint get what is eactly .class(i am not talking about .class file ) and where did it come from


I believe this field is added by the compiler. When you access this field, the compiler will replace it with code that will get you the Class instance that represents the class. (although, admittingly, I am a bit lacking on details about this)

Henry

Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Rajesh Tarte
Ranch Hand

Joined: Nov 02, 2006
Posts: 33

Thanks for response but i have few doubts

one
We have three classes Object,Class,ANYCLASS
then as per java Object is superclass of ANYCLASS and Class --> no doubts on this
but what is the relation ship between ANYCLASS and Class at compiletime and runtime?

1>Does Class becomes superclass for ANYCLASS at runtime?
Rajesh Tarte
Ranch Hand

Joined: Nov 02, 2006
Posts: 33

is the above rule apply for Object class also?
because i read in book as

Object is instance of Class
Class is instance of Object

Class is instance of Class

and ANYCLASS is instance of Class and Object

what they called it as a circular dependency...
salvin francis
Ranch Hand

Joined: Jan 12, 2009
Posts: 917

Class is a subclass of Object.
Any class you define is a subclass of Object.

Thats all there is to understand !!!


My Website: [Salvin.in] Cool your mind:[Salvin.in/painting] My Sally:[Salvin.in/sally]
Rajesh Tarte
Ranch Hand

Joined: Nov 02, 2006
Posts: 33

That i already posted


then as per java Object is superclass of ANYCLASS and Class --> no doubts on this
what i need is

but what is the relation ship between ANYCLASS and Class at compiletime and runtime?

1>Does Class becomes superclass for ANYCLASS at runtime?

because
is Object.class isInstance Class.class is true
and CLass.class isInstance Object.class is true
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18531
    
  40

but what is the relation ship between ANYCLASS and Class at compiletime and runtime?

1>Does Class becomes superclass for ANYCLASS at runtime?


Instances of the Class class type are merely used to introspect the classes. Thre is no inheritance hierarchy between the Class instance, and the class type that it is used to introspect (unless of course, it is the Class instance for the Object type).


because
is Object.class isInstance Class.class is true
and CLass.class isInstance Object.class is true


I don't know why you are confused here. Object.class is an instance of the Class class type. Class.class is an instance of the Class class type. So they are of the same class type.

Henry
Rajesh Tarte
Ranch Hand

Joined: Nov 02, 2006
Posts: 33


Does that mean ANYCLASS.class is instance of CLASS/Object/ANYCLASS?

Thanks henry

Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18531
    
  40

rajesh tarte wrote:
Does that mean ANYCLASS.class is instance of CLASS/Object/ANYCLASS?

Thanks henry



ANYCLASS.class is an instance of the Class class type. The Class class type is a subclass of the Object class type. As already mentioned, there are no other inheritance hierarchy relations between instances of the Class class, and the classes that they are introspecting.

Henry
 
 
subject: what exactly meant by ANYCLASS.class
 
Similar Threads
compare: are two objects from the same class
Instance of "Object" class
Class litral ??
Instance Of
Loading java applet from a cab file failed