Reflection or hashmaps? Suppose you are writting a graphical application where you have objects lying around and users have the posibility of clicking on them. That said, you want to display the clicked object information somehow.
I end up reading Accessible interface from accessibility java package and AccessibleContext class... Before that, I wrote testing code using hash maps for properties instead of class fields. And lastly, I thought in Reflection after reading that JavaBeans use instrospection.
What would you recommend in such applications?
Using reflection and introspection sounds like a better approach than using HashMaps. Instead of using this API directly, I would recommend an abstraction layer like Commons BeanUtils, which will allow you to work with classes adhering to the JavaBean standard in an easy manner.
Here's the User Guide complete with examples.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With