Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help needed with class literal

 
Ranjitha Serginaro
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was going through literals in javadocs where i came across this sentence "Finally, there's also a special kind of literal called a class literal, formed by taking a type name and appending ".class"; for example, String.class. This refers to the object (of type Class) that represents the type itself." which doesn't make any sense to me even though i paid attention to all the other topics prior to this. If any one could explain with examples or references it would be greatly appreciated. The link to the javadocs page displaying this is below.
http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34974
379
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can write without having to use the new operator. This is true for the class object too.

No "new" to be found in that code. The Class class isn't used much until you do more advanced Java like reflection. At which point, it is used for Reflection to look up methods/fields on the Class.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic