Class MultilineToStringStyle

All Implemented Interfaces:
Serializable

public class MultilineToStringStyle extends RecursiveToStringStyle
使用ToStringBuilder创建一个“deep”toString。 而是像RecursiveToStringStyle这样的单行, 创建类似ToStringStyle.MULTI_LINE_STYLE的多行字符串。
 public class Job {
   String title;
   ...
 }

 public class Person {
   String name;
   int age;
   boolean smoker;
   Job job;
   ...

   public String toString() {
     return new ReflectionToStringBuilder(this, new MultilineRecursiveToStringStyle()).toString();
   }
 }
 
Since:
Java 17+
Author:
Kimi Liu
See Also:
  • Constructor Details

    • MultilineToStringStyle

      public MultilineToStringStyle()
  • Method Details

    • appendDetail

      public void appendDetail(StringBuffer buffer, String fieldName, Object value)
      Description copied from class: ToStringStyle

      Append to the toString an Object value, printing the full detail of the Object.

      Overrides:
      appendDetail in class RecursiveToStringStyle
      Parameters:
      buffer - the StringBuffer to populate
      fieldName - the field name, typically not used as already appended
      value - the value to add to the toString, not null
    • appendDetail

      protected void appendDetail(StringBuffer buffer, String fieldName, Object[] array)
      Description copied from class: ToStringStyle

      Append to the toString the detail of an Object array.

      Overrides:
      appendDetail in class ToStringStyle
      Parameters:
      buffer - the StringBuffer to populate
      fieldName - the field name, typically not used as already appended
      array - the array to add to the toString, not null
    • reflectionAppendArrayDetail

      protected void reflectionAppendArrayDetail(StringBuffer buffer, String fieldName, Object array)
      Description copied from class: ToStringStyle

      Append to the toString the detail of an array type.

      Overrides:
      reflectionAppendArrayDetail in class ToStringStyle
      Parameters:
      buffer - the StringBuffer to populate
      fieldName - the field name, typically not used as already appended
      array - the array to add to the toString, not null
    • appendDetail

      protected void appendDetail(StringBuffer buffer, String fieldName, long[] array)
      Description copied from class: ToStringStyle

      Append to the toString the detail of a long array.

      Overrides:
      appendDetail in class ToStringStyle
      Parameters:
      buffer - the StringBuffer to populate
      fieldName - the field name, typically not used as already appended
      array - the array to add to the toString, not null
    • appendDetail

      protected void appendDetail(StringBuffer buffer, String fieldName, int[] array)
      Description copied from class: ToStringStyle

      Append to the toString the detail of an int array.

      Overrides:
      appendDetail in class ToStringStyle
      Parameters:
      buffer - the StringBuffer to populate
      fieldName - the field name, typically not used as already appended
      array - the array to add to the toString, not null
    • appendDetail

      protected void appendDetail(StringBuffer buffer, String fieldName, short[] array)
      Description copied from class: ToStringStyle

      Append to the toString the detail of a short array.

      Overrides:
      appendDetail in class ToStringStyle
      Parameters:
      buffer - the StringBuffer to populate
      fieldName - the field name, typically not used as already appended
      array - the array to add to the toString, not null
    • appendDetail

      protected void appendDetail(StringBuffer buffer, String fieldName, byte[] array)
      Description copied from class: ToStringStyle

      Append to the toString the detail of a byte array.

      Overrides:
      appendDetail in class ToStringStyle
      Parameters:
      buffer - the StringBuffer to populate
      fieldName - the field name, typically not used as already appended
      array - the array to add to the toString, not null
    • appendDetail

      protected void appendDetail(StringBuffer buffer, String fieldName, char[] array)
      Description copied from class: ToStringStyle

      Append to the toString the detail of a char array.

      Overrides:
      appendDetail in class ToStringStyle
      Parameters:
      buffer - the StringBuffer to populate
      fieldName - the field name, typically not used as already appended
      array - the array to add to the toString, not null
    • appendDetail

      protected void appendDetail(StringBuffer buffer, String fieldName, double[] array)
      Description copied from class: ToStringStyle

      Append to the toString the detail of a double array.

      Overrides:
      appendDetail in class ToStringStyle
      Parameters:
      buffer - the StringBuffer to populate
      fieldName - the field name, typically not used as already appended
      array - the array to add to the toString, not null
    • appendDetail

      protected void appendDetail(StringBuffer buffer, String fieldName, float[] array)
      Description copied from class: ToStringStyle

      Append to the toString the detail of a float array.

      Overrides:
      appendDetail in class ToStringStyle
      Parameters:
      buffer - the StringBuffer to populate
      fieldName - the field name, typically not used as already appended
      array - the array to add to the toString, not null
    • appendDetail

      protected void appendDetail(StringBuffer buffer, String fieldName, boolean[] array)
      Description copied from class: ToStringStyle

      Append to the toString the detail of a boolean array.

      Overrides:
      appendDetail in class ToStringStyle
      Parameters:
      buffer - the StringBuffer to populate
      fieldName - the field name, typically not used as already appended
      array - the array to add to the toString, not null