Reflection is a mechanism in java that allows to to get information about a class without needing to know the type of the class. The program below takes a java class name as a command line argument and shows you all of the methods and field names that are in the class.
You call the sample program like this:
java ReflectionTest java.util.Calendar
ReflectionTest takes the string you pass in on the command line and attempts to find a class by that name. If it finds one it gets an array of all the fields and displays their name and their values. It then gets an array of all the methods and displays their name and their return type.
Continue reading “Simple Introduction to Reflection”