The concept of Java Reflection API has been discussed here in the presentation. Some code snippets have also been introduces to illustrate the different interfaces and use cases.
http://bd.linkedin.com/in/imranhasanhira
https://www.facebook.com/KonaSoftware
https://www.linkedin.com/company/kona-software-lab-ltd-
4. Basic Idea
• Accessing a field in runtime
• Find a class
• Instantiate a object form the class
• Find it’s field
• Set value of the field on that object
• Calling a method in runtime
• Find a class
• Instantiate a object form the class
• Find it’s method
• Invoke the method (with/without parameter)
• Get the returned value
16. Reflection Drawbacks
• Performance overhead
• Dynamically type resolutions occlude JVM optimizations.
• Should be avoided in parts of code in performance sensitive applications
*Taken from a article of Dennis Sosnoski,
17. Reflection Drawbacks
• Performance overhead
• Dynamically type resolutions occlude JVM optimizations.
• Should be avoided in parts of code in performance sensitive applications
• Security Restrictions
• Requires a runtime permission, so your code may not run in a restricted
security context.
• Exposure of Internals
• Accessing private fields and methods
• Reflective code breaks abstractions*
18. References
Article from Oracle -
https://docs.oracle.com/javase/tutorial/reflect/
http://docs.oracle.com/javase/8/docs/api/index.html?java/lang/Class.
html
Dennis Sosnoski’s Article on Reflection -
http://www.ibm.com/developerworks/java/library/j-
dyn0603/index.html
Source Code Snippets -
https://github.com/imranhasanhira/java-reflection-annotation-test