> Can anyone provide a reasonable example of a situation that needs reflection and a short explanation of why?
We use it on our current project for dynamic configuration of our UI. All panel components share an interface and with a simple XML file we can reconfigure the frames and panels with no change to the compiled jar file. We also use it for our reporting engine to load column classes that can be plugged in to our table-based reports. These are simple usages of loading classes that share a common interface by supplying their class name and other properties in simple xml files.
Can you elaborate somewhat on the first example? Do you mean that depending on what the contents are of the XML file, different panels would appear which are created from classes that have their own content... but that the type and size of the panel are always the same? Because I don't see how you could use different sized panels each time, that would mess up the layout. Unless, I suppose, you somehow dynamically figure out how big each panel was and did calculations based on that also. The second example seems to make sense - you have a table and its layout set ahead of time, and based on what Strings are input, that table looks up the classnames (presumably each String represents a classname?) then fills the table with each of those classes, treating a class as a 'column'? That example seems to make sense, because if you wanted to be able to put anything in the table without recompiling, I guess reflection would be the only way to do that.
Last edited by BestJewSinceJC; Nov 10th, 2008 at 11:30 pm.
Reputation Points: 874
Solved Threads: 352
Posting Maven
Offline 2,758 posts
since Sep 2008