LoginSignup
3
3

More than 5 years have passed since last update.

【commons-lang3】 ToStringBuilder / ReflectionToStringBuilder のよく利用する(しそう)メソッド

Posted at

メモ



import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

public class Main {

    public static void main(String[] args) {

        // 基本
        System.out.println(ToStringBuilder.reflectionToString(new Main()));
        // フォーマット
        System.out.println(ToStringBuilder.reflectionToString(new Main(),
                ToStringStyle.SIMPLE_STYLE));

        // 一部パラメーターを除外する。
        System.out.println(ReflectionToStringBuilder.toStringExclude(new Main(), "id"));
        // 基本と同等
        System.out.println(ReflectionToStringBuilder.toString(new Main()));
        // フォーマットと同等
        System.out.println(ReflectionToStringBuilder.toString(new Main(), ToStringStyle.SIMPLE_STYLE));
    }
}

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3