Java Reflection

What’s Going On in There? Java Reflection for Program Insight

By Sridhar M S

Go to page: 1  2 3 Next

In programming terms, reflection is a feature that allows you to see the internal composition of a program—everything from its variables to its method declarations. As its name indicates, the Java Reflection API enables this functionality in Java.

The Java Reflection API provides insight into the classes, interfaces, and objects in a given Java Virtual Machine (JVM). Developers commonly use the API to accomplish the following tasks, which explains why it is so often used to develop tools such as debuggers and Integrated Development Environments (IDEs):

  • Determine the class of an object.
  • Get information about a class’s modifiers, fields, methods, constructors, etc.
  • Get information about an interface’s constants and method declarations.
  • Create an instance of a class whose name is not known until runtime, but rather available at design time or provided as a runtime parameter.
  • Get and set the value of an object’s field, even if the field name is unknown to your program until runtime.
  • Invoke a method on an object, even if the method is not known until runtime.

Etiquetas: , ,