• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Regarding Reflection...  RSS feed

 
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

Can somebody gimme some info about what is Reflection and how is it used with some good examples?

Regards,
Sriram.
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Reflection (see Wikipedia entry) is all about interacting with the runtime environment as it's running. Languages that support reflection give you different means of getting information from runtime objects (like classes) and some even go as far as letting you dynamically create new classes and methods at runtime.

In Java, Reflection can be used to get information about in-memory objects, the classes that they are instances of, the methods in those classes, what kind of parameters they take, what kind of fields are defined in the class, are they public/private/protected, etc. etc. etc.

Here is a crude example: this program reads a method name from the command line, finds it in the class and tries to invoke it on the object.





There's a good tutorial on the Reflection API from java.sun.com that you can follow to get a nice introduction to it.
 
and POOF! You're gone! But look, this tiny ad is still here:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!