A class literal is something like String.class
, i.e. a compile-time literal representing the String
class.
In short, reflection is a language feature that allows you to "reflect" on the code, i.e. you can query the system for classes, methods, fields, etc. and use that data to create new instances, call methods or change the value of fields.
Reflection might be useful to create objects of classes that are not known at compile-time, but are on the classpath at runtime. Several extension frameworks make use of that, mostly by providing fully qualified class names in some text file (e.g. com.acme.SomeFancyClass
), getting the associated Class
object from the class loader and creating new instances.
Other frameworks (e.g. Apache Common's builder objects, OGNL, Java Beans etc.) use reflection to query the available properties (getters and/or matching setters) that can be accessed (through calls to those getters/setters).
However, if you are new to Java, I'd recommend diving into other language features before loosing yourself in the depth of the reflection facility.