@Override
public String toString() {
return ToStringBuilder.reflectionToString(this);
}
I'm actually looking right now on how to get its output to be a bit prettier. ReflectionStringBuilder seems to offer some more customization. Specifically I like this:
@Override
public String toString() {
StandardToStringStyle style = new StandardToStringStyle();
style.setFieldSeparator(", ");
style.setUseClassName(false);
style.setUseIdentityHashCode(false);
return new ReflectionToStringBuilder(this, style).toString();
}
发布评论
评论(2)
Apache ToStringBuilder 有开箱即用的不错的实现:
我现在实际上正在研究如何使其输出变得更漂亮。 ReflectionStringBuilder 似乎提供更多定制。具体来说,我喜欢这样:
输出如下所示:
Apache ToStringBuilder has a decent implenentation out of the box:
I'm actually looking right now on how to get its output to be a bit prettier. ReflectionStringBuilder seems to offer some more customization. Specifically I like this:
The output looks like this:
我只是使用我的 IDE 为我生成 toString。如果我更改代码,我会删除该方法并重新生成。
I just use my IDE to generate the toString for me. If I change the code, I delete the method and regenerate.