Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what is java reflection

 
sudheer kiran
Ranch Hand
Posts: 237
Firefox Browser MyEclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is java reflection and in which case it is useful..i am asking just for to know what is what.
 
Ryan Clark
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Sudheer,

Java reflection is a technique your program can use to see and modify its own structure. If you don't know what kind of class you have or what its methods are, you can use reflection to find out, then instantiate and call methods on that object. And if I remember correctly, you can view method signatures through reflection, but you can't see the implementation.

As for practical application, I once had to write a web app that could test any kind of class (new classes could be added and we didn't want to change our app). To test them, I used reflection to instantiate the object and get a list of methods to show the user. Once they picked a method, I'd let them enter data, called the method, and returned the output to the user.

Hope this helps! (It's my first post!)
 
Campbell Ritchie
Sheriff
Pie
Posts: 49442
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think it's helpful, Ryan, and welcome to JavaRanch

Sudheer K please check your private messages about an important administrative matter.
 
sudheer kiran
Ranch Hand
Posts: 237
Firefox Browser MyEclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi thanks for the info
 
Siddharth Naik
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is a good article on reflection:
http://www.ibm.com/developerworks/library/j-dyn0603/
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic