Reflection API

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

ClassWhat it does ?
Arrayallow you to dynamically create and manipulate arrays
Constructorgives information about constructor of a class
Fieldprovide information about field
Methodprovide information about method
Modifierprovide information about class and member access modifier
Proxysupports 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