Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

reflection in J2EE  RSS feed

 
sarah Marsh
Ranch Hand
Posts: 282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello:

When should we use Java reflection in J2EE? Please give me some examples or some websites to take a look.

Thanks in advance!
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Reflection can be very useful in J2EE - it is one of the tool that let applications be extended without having to rewrite base classes. There are no hard and fast rules about where you use it though. A good example of where it is useful is say loading values into a DTO. You could write a helper class per DTO to explicitly call each set method, or write one class which uses reflection to find the public set methods and call them. One big warning though, using reflection moves a lot or compile time errors in to becoming runtime errors. This means you can loose visibility of what might be going wrong in your code: a change of method name can result in parts of your code not being called anymore. If it were being explicitly called, the compiler would complain, if you are calling it through reflection, there may be no error at all.
 
sarah Marsh
Ranch Hand
Posts: 282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, Paul.

I have some difficulties to understand the reflection part of the code from SUN's Transfer Object. I read the reflection about Invoking methods by name. Any complete examples (maybe very detail explanations) of Transfer Object using reflection?

Thanks!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!