16. Dynamic Programming Through ReflectionReflection is a mechanism for discovering data about a program at runtime. Reflection in Java enables you to discover information about fields, methods, and constructors of classes. You can also operate on the fields and methods that you discover. Reflection enables what is commonly referred to as dynamic programming in Java. Reflection in Java is accomplished using the Java Reflection API. This API consists of classes in the java.lang and the java.lang.reflect packages. The things that you can do with the Java Reflection API include the following:
The Java reflection API is commonly used to create development tools such as debuggers, class browsers, and GUI builders. Often in these types of tools, you need to interact with classes, objects, methods, and fields, and you do not know which ones at compile time. So the application must dynamically find and access these items. |