• Post Reply Bookmark Topic Watch Topic
  • New Topic

Reflection  RSS feed

 
sreejith panampilly
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is reflection? what is the use of it?
 
Naseem Khan
Ranch Hand
Posts: 809
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Reflection is a feature of java programming language by which you can examine a class at runtime.

For example, you can find information about the different members of a class by using reflection APIs.

Different IDEs and RAD does introspection of java classes by reflection. For that, you need to use java.lang.reflect package that comes with j2sdk

Naseem
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just for completeness, you can go well beyond examining classes to create instances and invoke methods. Start with the Class class and see methods to create an instance, get fields, get methods, etc.

Usually reflection works best in the "tool" category of code, maybe an IDE or a utility that can generate XML from any object. I very rarely use anything besides Class.forName().newInstance() in regular business code.
 
Srinivas Kalvala
Ranch Hand
Posts: 257
Firefox Browser Hibernate Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Reflection are mainly used by Tools to analyze the package or class structure dynamically.

For example, one way to use reflection is to populate all the bean classes with some values, which are taken from a file and serialize them.

At runtime you can define which class you want to use and populate and send it to the requirement routine.

But one thing.... Reflections are costlier in terms of performance. Have a look at performance factor.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!