• Post Reply Bookmark Topic Watch Topic
  • New Topic

is class a static member?  RSS feed

 
Kaarthick Ramamoorthy
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

In the following code, How Test.class works? Is that class is a static member of Test or Object?. Please clarify me.



Thanks in advance
Kaarthick
 
Marco Ehrentreich
best scout
Bartender
Posts: 1294
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

the Class objects you're talking about are somewhat special. They are dynamically created by the class loader in the JVM of an application at runtime the first time a class is used (take care of upper case names: Class is the class named "Class").

The ".class" language construct is neither a static member of Object nor of Test. It's a Java language feature called class literal!

There's one Class object created per class and all Class objects belong to class Class (sounds funny ).

Your example Test.class is the same as Class<Test> using generics. Other usual ways for retrieving a Class object is to use the Class.forName() method so that the JVM actually has to load a class. Or if you have already an object of your class type you can use the getClass() method inherited from Object.

I hope now it's a bit clearer... Oh, perhaps you want to take a look at the API doc of class Class.

Marco
[ March 27, 2008: Message edited by: Marco Ehrentreich ]
 
Kaarthick Ramamoorthy
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your interesting information.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!