Reflections: Reflection in Java Provides Ability To Inspect and Modify The Runtime Behavior
Reflections: Reflection in Java Provides Ability To Inspect and Modify The Runtime Behavior
// with reflection
Class<?> c = Class.forName("classpath.and.classname");
Object dog = c.newInstance();
Method m = c.getDeclaredMethod("bark", new Class<?>[0]);
m.invoke(dog);
In Java, reflection is more about introspection, because you can not
change structure of an object. There are some APIs to change
accessibilities of methods and fields, but not structures.
1. JUnit – uses reflection to parse @Test annotation to get the test methods
and then invoke it.
2. Spring – dependency injection, read more at Spring Dependency
Injection
3. Tomcat web container to forward the request to correct module by
parsing their web.xml files and request URI.
4. Eclipse auto completion of method names
5. Struts
6. Hibernate
We should not use reflection in normal programming where we already have
access to the classes and interfaces because of following drawbacks.