Search in sources :

Example 6 with ToStringBuilder.reflectionToString

use of org.apache.commons.lang3.builder.ToStringBuilder.reflectionToString in project fb-contrib by mebigfatguy.

the class CSBTS_StringToStringSample method main.

public static void main(String[] args) {
    Person p = new Person("John Doe", 2);
    ToStringBuilder x = new ToStringBuilder(p);
    ToStringBuilder y = new ToStringBuilder(p);
    // INCORRECT USAGE : The same as invoking Object.toString
    System.out.println("P " + new ToStringBuilder(p).toString());
    // Consider using for non final classes to support a string
    // representation for derived types
    System.out.println("P " + ToStringBuilder.reflectionToString(p));
    GenderPerson p2 = new GenderPerson("Jane Doe", 2, SEX.Female);
    System.out.println("GP " + new ToStringBuilder(p2).append("name", p2.name).append("age", p2.age).append("sex", p2.sex).toString());
    // Y now has an append
    y.append("name", p.name);
    System.out.println("P - Once Again " + y.toString());
    System.out.println("P - Again " + x.toString());
}
Also used : ToStringBuilder(org.apache.commons.lang3.builder.ToStringBuilder)

Aggregations

ToStringBuilder (org.apache.commons.lang3.builder.ToStringBuilder)6 Element (electric.xml.Element)2 Pattern (blue.soundObject.pattern.Pattern)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 Collection (java.util.Collection)1