File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Why and When to use reflections Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Why and When to use reflections" Watch "Why and When to use reflections" New topic

Why and When to use reflections

Harsha Hegde

Joined: Jan 12, 2009
Posts: 17

Hi folks,
I recently studied the concept of reflections in java, but I am unable to find the practical use of it?
Can anyone give a practical example where some problem can be solved only by reflection or reflection is the best way to sole that problem.
Daesung Park
Ranch Hand

Joined: Mar 22, 2007
Posts: 68
Reflection is widely used, and dependency-injection is one of the examples.
You can describe concrete class name in your configuration file and then create an instance of the class at runtime by reflection.

Daesung Park

arulk pillai
Ranch Hand

Joined: May 31, 2007
Posts: 3371
You can also use in your custome annotations.

[] | [Java job hunting know how] | [Java resumes]
lin qun

Joined: Feb 20, 2009
Posts: 5
setter and getter methods.
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46360
To the Java Tutorials! You will find a whole section about reflection.
Kuldeep Tewari
Ranch Hand

Joined: May 22, 2006
Posts: 35
Some of the realtime examples include : your IDE's intellisense, Dynamic proxies, dependency injection etc.
Bert Bates

Joined: Oct 14, 2002
Posts: 8898
intermediate level!

Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
I agree. Here's the link:
subject: Why and When to use reflections
jQuery in Action, 3rd edition