This week's book giveaway is in the Programmer Certification forum.
We're giving away four copies of OCP Oracle Certified Professional Java SE 21 Developer Study Guide: Exam 1Z0-830 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.
  • 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

is class a static member?

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
best scout
Posts: 1294
Scala IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your interesting information.
 
What are you doing? You are supposed to be reading this tiny ad!
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic