• Post Reply Bookmark Topic Watch Topic
  • New Topic

what is the meaning of ClassName.class?  RSS feed

 
tarun mall
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi friends I was reading an android tutorial and I found following line:



What is the meaning of MyPreferencesActivity.class

I also looked into this thread: http://www.coderanch.com/t/383653/java/java/does-ClassName-class-mean-static but the link of the java reference provided in the thread is not working.
 
Greg Charles
Sheriff
Posts: 3015
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It means that the parameter passed is actually the class, not an instance of the class, or a variable with the same name. I don't know what he Intent object does, but it must use the class you give it in some way, probably for reflection. The thread you linked actually asks two questions: the one you ask here and also about static inner classes. I didn't see a broken link in it though.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Every class in Java has an associated instance of java.lang.Class that contains metadata about the class--its field names and types, method declarations, parent class, etc. When you see ClassName.class that is known as a class literal. (http://docs.oracle.com/javase/specs/jls/se5.0/html/expressions.html#15.8.2) It is a compile-time constant that evaluates to a reference to that class's Class object.
 
Mike Simmons
Ranch Hand
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, a compile-time constant expression is something else, that does not include class literals. But a class literal does refer to something that doesn't change, and is certainly understood by the compiler at compile time.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike Simmons wrote:Well, a compile-time constant expression is something else, that does not include class literals.


My bad. I could have sworn it did. I guess I should have double-checked first. Thanks for the correction.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!