4.9.1 Reflection

Java is a safely typed language, in that the result of any expression is well-defined either as a value of a known type, or a known exception. Most of the programming you will do in Java should use the type system, since compilation errors will save you much heartache in debugging systems at runtime.

However, there are application areas which require the type of objects to be examinable in detail, such as IDEs and remote method invocation. To support these sorts of applications, Java provides reflection, where the class of an object can be determined at runtime, and this class can be examined to determine which methods are available, and even invoke these methods with dynamically created arguments.

The key to reflection is the java.lang.Class, which allows much information to be determined about a class. This leads onto the other reflection classes such as java.lang.reflect.Method.

For more detailed information, try the reflection tutorial.

Ian Wakeman 2005-02-22