The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Help needed with class literal Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Help needed with class literal" Watch "Help needed with class literal" New topic

Help needed with class literal

Ranjitha Serginaro

Joined: Jan 10, 2013
Posts: 2
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.
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33134

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.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
I agree. Here's the link:
subject: Help needed with class literal
It's not a secret anymore!