Java - Best Way to Display Object Properties

Reflection or hashmaps? Let's say you are writing a graphical application where you have objects and users can click on them. However, you want to somehow display information about the clicked objects.

I am finishing reading the interface Accessible

from the java accessibility package and class AccessibleContext

... Prior to that, I wrote test code using hash maps for properties instead of class fields. And finally, I thought in Reflection after reading that JavaBeans uses instrospection.

What do you recommend in such applications?


source to share

1 answer

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 that adhere to the JavaBean standard in an easy way.

Here User Guide contains examples.



All Articles