Sunday, August 19, 2007

Java Reflection

An executing Java program can introspect itself using java.lang.reflect.

Classes:
  • Class - represents classes and interfaces
  • Constructor - represents class constructors
  • Method - represents class methods
  • Fields - represent class fields
  • Modifier - represents the modifier of a field
  • Array - represents an array

Methods:

  • isInstance - simulates the instanceof operator
  • newInstance - create a new instance of the Class or Array
  • getDeclaringClass - get the Class which declared the Method, Constructor etc.
  • getDeclaredConstructors - get Constructor's declared by the class
  • getDeclaredMethods - get Method's declared by the class
  • getDeclaredFields - get the Field's declared by the class
  • getModifiers - get the Modifier's of a field

No comments: