Dependency Injection's equivalent Java reflection invocations
As we know that there are 3 types of injections supported by any IoC framework, following are the equivalent function points in the reflection package (java.lang.reflect):
1) Constructor Injection - <T> Constructor.newInstance(Object... initargs) 2) Method Injection - Object Method.invoke(Object obj, Object... args) 3) Field Injection - void Field.set(Object obj, Object value)
Interestingly all these reflection classes are subclasses of java.lang.reflect.AccessibleObject and are final. Also the complete mechanics of Injection semantics hinges on the accessible flag defined in java.lang.reflect.AccessibleObject. Please see javadocs for effective explanation.
Categories: Uncategorized