2 min read

Reflection in Java

Code Introspection is the ability to inspect the code in a system and to see object types. Reflection is the ability to make use of code introspection to modify classes at runtime.

Reflection is important because it allows a programmer to develop programs that do not have to “know” everything at compile time, which makes them more dynamic. Many modern frameworks make use of reflection extensively. The Spring framework, for example, uses reflection to create its beans.

The java.lang.reflect library provides classes and interfaces for obtaining reflective information about classes and objects.

Some common uses of reflection in Java include:

According to the Core Java 2 book,

The reflection library gives you a a very rich and elaborate toolset to write programs that manipulate Java code dynamically…heavily used in JavaBeans, the component architecture for Java.. Using reflection, Java can support tools like the ones to which users of Visual Basic have grown accustomed.

References:

← All posts