How to use ReflectionToStringBuilder class?
toString() method sometimes can become a time consuming process. If you have a little class attributes to be returned by the
toString() method it might be alright, but when you deal with a many fields it will surely take your time to update this method every time a new attributes come and go.
Here come the
ReflectionToStringBuilder class that can help you to automate the process of implementing the
toString() method. This class provides a static
toString() method that takes at least a single parameter that refer to an object instance from where the string will be generated.
We can also format the result of the generated string. In the example below we create the to string method with a
ToStringStyle.SIMPLE_STLYE and we can also output the transient and static attributes if we want; which by default omitted.