• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

The .class property

 
Dmitriy Pavlyuk
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Explain me please, where from the .class property appears in any Object descendant. It's not in Object!
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am going to guess that you are asking about reflection.
The JVM creates the Class object for each class.
From the API for Class:

Class has no public constructor. Instead Class objects are constructed automatically by the Java Virtual Machine as classes are loaded and by calls to the defineClass method in the class loader.

 
Junilu Lacar
Bartender
Posts: 7605
54
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or perhaps you are referring to Class Literals, which are evaluated at compile time and evaluate to the Class object of the named type. Refer to JLS �15.8.2 Sample usage below:

[This message has been edited by JUNILU LACAR (edited June 28, 2001).]
 
rani bedi
Ranch Hand
Posts: 358
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whats the use of the Class Literal?
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, it allows you to refer to a particular Class object directly, without having to create an instance of the class first. If I want a StringBuffer Class object, it's more efficient to say "StringBuffer.class" than "new StringBuffer().getClass()".
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic