Introduction to Reflection

Reflection means ability of a software to analyze itself. In Java, Reflection API provides facility to analyze and change runtime behaviour of a Class, at runtime.

For example, using reflection at the runtime you can determine what method, field, constructor or modifers a class supports.


What is reflect package ?

java.lang.reflect package encapsulates several important interfaces and classes. These classes and interface define methods which are used for reflection.


Some Important Classes of java.lang.reflect package

Class What it does ?
Array allow you to dynamically create and manipulate arrays
Constructor gives information about constructor of a class
Field provide information about field
Method provide information about method
Modifier provide information about class and member access modifier
Proxy supports dynamic proxy classes

Apart from these classes java.lang.Class is another very important class used in Reflection API.


Uses of Reflection

  • Developing IDE
  • Debugging and Test tools
  • Loading drivers and providing dynamic information

Disadvantages of Reflection

  • Low performance
  • Security risk
  • Violation of Oops concept