• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

what exactly meant by ANYCLASS.class

 
Ranch Hand
Posts: 33
Eclipse IDE Flex Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not user interface related. Moving to a better forum.
 
Rajesh Tarte
Ranch Hand
Posts: 33
Eclipse IDE Flex Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how to move it?
 
Rob Spoor
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Only bartenders and sheriffs can move threads. I already did it.
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Rajesh Tarte
Ranch Hand
Posts: 33
Eclipse IDE Flex Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 33
Eclipse IDE Flex Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Bartender
Posts: 2911
150
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Class is a subclass of Object.
Any class you define is a subclass of Object.

Thats all there is to understand !!!
 
Rajesh Tarte
Ranch Hand
Posts: 33
Eclipse IDE Flex Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 33
Eclipse IDE Flex Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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

Thanks henry

 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
No matter. Try again. Fail again. Fail better. This time, do it with this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic