Reflection is a very useful approach to deal with the Java class at runtime.
It is commonly used by programs which require the ability to examine or modify the runtime behavior of applications running in the JVM.
It is also possible to instantiate new objects, invoke methods and get/set field values using reflection.
Usage of Reflection in Java
Code analyzer tools
PMD, FindBugs etc. analyzes any class file passed to them using Reflection
Auto completion of method names in IDEs
IDE (Like, Eclipse) provides method suggestions whenever we hit CTRL+SPACE
Auto code generation
Struts, Spring etc. uses Reflection for Auto code generation.
Marshaling and unmarshalling
Marshalling is the process of transforming the memory representation of an object to a data format suitable for storage or transmission.
JAXB, Jattison etc. libraries heavily use reflection for XML (or JSON) to / from java beans code. They look up all annotated attributes in java bean, analyze their overall attributes and generate XML tags for them.
Creating the beans
Spring framework uses reflection to injecting bean dependencies defined in configuration files. Spring 3 onwards, Annotations based dependencies can be analysed using reflection.
Parsing annotations
ORMs like Hibernate use the configuration files (not they use annotations) for defining the relationship between entities and database schemas which is processed using reflection.
No comments:
Post a Comment
Note: only a member of this blog may post a comment.