Reflection API is not something which helps you to make the things easier in general purposes. Generally, reflection is not used in the applications running in generic enterprise containers or platforms. Nevertheless, reflection will not work when there is a SecurityManager available, unless the policies are configured to allow the use of reflection. Reflection API could be helpfully used if you are working in a reflection-allowed environment, where the direct collaboration with the Java classes is essential. Developing your own container for a specific architecture is an example for such.
Hi Devaka,
I got your point: it is not used in general purpose programming.
Can you specifically say what popular frameworks java reflection is used and what problem framework implementers try to solve using java reflection ?
I'm expecting a high level answer.
As I said before, reflection is used when it is needed to get into the other classes in deeper level. So in most of the cases, these implementors have the container-behavior. For instance, dependency injection is mostly done with the use of reflection. If you need a framework as an example for that, Spring does it's dependency injection jobs with the help of reflection API.
Devaka Cooray wrote:As I said before, reflection is used when it is needed to get into the other classes in deeper level. So in most of the cases, these implementors have the container-behavior. For instance, dependency injection is mostly done with the use of reflection. If you need a framework as an example for that, Spring does it's dependency injection jobs with the help of reflection API.
thanks very much.....because I use to work with spring framework but I really don't know what goes behind the sense. Now I realized I have to know lot more rather than using just the spring for dependency injection.
Devaka Cooray wrote:As I said before, reflection is used when it is needed to get into the other classes in deeper level. So in most of the cases, these implementors have the container-behavior. For instance, dependency injection is mostly done with the use of reflection. If you need a framework as an example for that, Spring does it's dependency injection jobs with the help of reflection API.
thanks very much.....because I use to work with spring framework but I really don't know what goes behind the sense. Now I realized I have to know lot more rather than using just the spring for dependency injection.
yes..... definitely right... Spring dependency injection uses the java reflection api. it is a one example. I found another real world usages of java reflection by reading onjava article. I will mention them as below . perhaps helpful to you.
Eclipse manage to do all that helpful auto-completion of method names using reflection
Tomcat go from a class name in a web.xml file to a running servlet fielding web requests by exercising reflection.
when mapping objects to tables in a database at runtime in hibernate
You will also find reflections used behind the scenes in a large number of areas. For example, if you used JAXB, then a lot of the marshalling / unmarshalling of the XML will be done using reflections. Using Annotations in your code often results in reflections being used behind the scenes. When performing unit testing, particularly when mocking classes and/or methods, often has lots of reflections code being used.
Andrew Monkhouse wrote:You will also find reflections used behind the scenes in a large number of areas. For example, if you used JAXB, then a lot of the marshalling / unmarshalling of the XML will be done using reflections. Using Annotations in your code often results in reflections being used behind the scenes. When performing unit testing, particularly when mocking classes and/or methods, often has lots of reflections code being used.
As you said before, Java reflection is working behind the scene for annotations.Now I have a doubt, How Java reflection take care of annotations........simply I would ask how annotation processing happens with use of Java reflection
Thinker
Nuwan Arambage
Rototillers convert rich soil into dirt. Please note that this tiny ad is not a rototiller:
Gift giving made easy with the permaculture playing cards