What are Class Literals ? – here is a definition from JLS
15.8.2 Class Literals
A class literal is an expression consisting of the name of a class, interface, array, or primitive type followed by a `.’ and the token class. The type of a class literal is Class. It evaluates to the Class object for the named type (or for void) as defined by the defining class loader of the class of the current instance.
Class Literals as Runtime-Type Tokens.
One of the changes in JDK 5.0 is that the class
java.lang.Class is generic. It’s an interesting example of using genericity for something other than a container class.
Class has a type parameter
T, you might well ask, what does
T stand for? It stands for the type that the
Class object is representing.
For example, the type of
Class<String>, and the type of
Class<Serializable>. This can be used to improve the type safety of your reflection code.
In particular, since the
newInstance() method in
Class now returns a
T, you can get more precise types when creating objects reflectively