reflection in J2EE
posted 12 years ago
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.