java reflection - what is - 101 tutorial


The name reflection is used to describe code which is able to inspect other code in the same system (or itself).
A simple code example of this in Java (imagine the object in question is foo) :
Method method = foo.getClass().getMethod("doSomething", null);
method.invoke(foo, null);
One very common use case in Java is the usage with annotations. JUnit 4, for example, will use reflection to look through your classes for methods tagged with the @Test annotation, and will then call them when running the unit test.
There are some good reflection examples to get started : at http://java.sun.com/developer/technicalArticles/ALT/Reflection/index.html