/java/

Apache Commons ToStringBuilder

2013-08-20 21:05:31

If like me you hate something like this:

    @Override
    public String toString() {
        return "Post{" + "id=" + id + ", title=" + title + ", desc=" + desc + ""
                + ", comment=" + comment + ", type=" + type + ""
                + ", typeId=" + typeId + ", isArticle=" + isArticle + '}';
    }

You can use this:

    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this);
    }

maven repository


<dependency>
    <groupid>org.apache.commons</groupid>
    <artifactid>commons-lang3</artifactid>
    <version>3.1</version>
</dependency>