I used ToStringBuilder.reflectionToString(class)
in commons-lang, to implement toString()
for simple DTOs. Now I\'m trying to use Google Guava instead
MoreObjects.toStringHelper
is intended to help you write toString()
methods with a consistent format easily, but it gives you control over what fields you include in toString()
and should have performance comparable to writing it out manually. reflectionToString
is shorter to type, but it doesn't give you explicit control over the included fields and, well, it uses reflection. I don't see it as a better alternative.
As a side note, I think using toStringHelper
looks a lot cleaner if you put one add
call per line.
Guava docs