• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

what is the meaning of ClassName.class?

 
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.
 
Sheriff
Posts: 3034
12
Mac IntelliJ IDE Python VI Editor Java
  • 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.
 
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.
 
Master Rancher
Posts: 3313
31
  • 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.
 
Roses are red, violets are blue. Some poems rhyme and some don't. And some poems are a tiny ad.
create, convert, edit or print DOC and DOCX in Java
https://products.aspose.com/words/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!