What is a class literal in Java?

gameover picture gameover · Jan 29, 2010 · Viewed 34k times · Source

From the Java tutorial:

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.

To what type of variable can this literal be assigned to?

Please give a small example if possible.

Answer

Steven Schlansker picture Steven Schlansker · Jan 29, 2010
Class<String> c = String.class;

Check out the Javadoc for java.lang.Class to see what you can do with one of these little guys - mostly related to reflection