0

I'm pretty new to java, and on the java tutorial it uses the terms "class literal" and "reflection".

From the reflection api trail from the java website, http://docs.oracle.com/javase/tutorial/reflect/index.html, it says

Extensibility Features An application may make use of external, user-defined classes by creating instances of extensibility objects using their fully-qualified names.

What does that mean?

Thanks.

Ankur Lathi
  • 7,636
  • 5
  • 37
  • 49
Jonathan Lam
  • 16,831
  • 17
  • 68
  • 94
  • See [What is a class literal in Java?](http://stackoverflow.com/questions/2160788/what-is-a-class-literal-in-java) – Joe Jul 30 '13 at 15:12

1 Answers1

2

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.

Thomas
  • 87,414
  • 12
  • 119
  • 157