Class ToStringBuilder

java.lang.Object
org.aoju.bus.core.builder.ToStringBuilder
All Implemented Interfaces:
Serializable, Builder<String>
Direct Known Subclasses:
ReflectionToStringBuilder

public class ToStringBuilder extends Object implements Builder<String>
协助实现Object.toString()方法

这个类支持为任何类或对象构建良好且一致的toString()这个类的目的是通过

  • allowing field names
  • handling all types consistently
  • handling nulls consistently
  • outputting arrays and multi-dimensional arrays
  • enabling the detail level to be controlled for Objects and Collections
  • handling class hierarchies

To use this class write code as follows:

 public class Person {
   String name;
   int age;
   boolean smoker;

   ...

   public String toString() {
     return new ToStringBuilder(this).
       append("name", name).
       append("age", age).
       append("smoker", smoker).
       toString();
   }
 }
 
Since:
Java 17+
Author:
Kimi Liu
See Also: