Annotation Type ToString


@Target(TYPE) @Retention(SOURCE) public @interface ToString
Generates an implementation for the toString method inherited by all objects, consisting of printing the values of relevant fields.

Complete documentation is found at the project lombok features page for @ToString.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static @interface 
    If present, do not include this field in the generated toString.
    static @interface 
    Configure the behaviour of how this member is rendered in the toString; if on a method, include the method's return value in the output.
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    boolean
    Include the result of the superclass's implementation of toString in the output.
    boolean
    Normally, if getters are available, those are called.
    Any fields listed here will not be printed in the generated toString implementation.
    boolean
    Include the name of each field when printing it.
    If present, explicitly lists the fields that are to be printed.
    boolean
    Only include fields and methods explicitly marked with @ToString.Include.
  • Element Details

    • includeFieldNames

      boolean includeFieldNames
      Include the name of each field when printing it. default: true
      Returns:
      Whether or not to include the names of fields in the string produced by the generated toString().
      Default:
      true
    • exclude

      String[] exclude
      Any fields listed here will not be printed in the generated toString implementation. Mutually exclusive with of().

      Will soon be marked @Deprecated; use the @ToString.Exclude annotation instead.

      Returns:
      A list of fields to exclude.
      Default:
      {}
    • of

      String[] of
      If present, explicitly lists the fields that are to be printed. Normally, all non-static fields are printed.

      Mutually exclusive with exclude().

      Will soon be marked @Deprecated; use the @ToString.Include annotation together with @ToString(onlyExplicitlyIncluded = true).

      Returns:
      A list of fields to use (default: all of them).
      Default:
      {}
    • callSuper

      boolean callSuper
      Include the result of the superclass's implementation of toString in the output. default: false
      Returns:
      Whether to call the superclass's toString implementation as part of the generated toString algorithm.
      Default:
      false
    • doNotUseGetters

      boolean doNotUseGetters
      Normally, if getters are available, those are called. To suppress this and let the generated code use the fields directly, set this to true. default: false
      Returns:
      If true, always use direct field access instead of calling the getter method.
      Default:
      false
    • onlyExplicitlyIncluded

      boolean onlyExplicitlyIncluded
      Only include fields and methods explicitly marked with @ToString.Include. Normally, all (non-static) fields are included by default.
      Returns:
      If true, don't include non-static fields automatically (default: false).
      Default:
      false