I have a bog-standard Java bean, MyJavaBean. Say it has 50 variables, and I have generated 50 getters and 50 setters with eclipse.
This bean is populated by some assembly line of business logic, and now I want to traverse all 50 elements. For example, to implement a to-string method. Naturally I don't want to call each getter method.
Now there are some obvious but long approaches:
implement the bean so that it keeps a collection of it's elements up to date as it goes, then just write a getter for that
manually implement an iterator by adding each element to a collection and returning that
So I have two questions:
if I have a bean with 50 elements, have I already made a mistake? Is this a negative pattern?
How can I do this in a cleverer way? Is there some library that will return a collection of elements given a JavaBean, using reflection or something similar?