Lombok - v0.10.8

lombok
Annotation Type ToString


@Target(value=TYPE)
@Retention(value=SOURCE)
public @interface ToString

Generates an implementation for the toString method inherited by all objects.

If the method already exists, then ToString will not generate any method, and instead warns that it's doing nothing at all. The parameter list and return type are not relevant when deciding to skip generation of the method; any method named toString will make ToString not generate anything.

By default, all fields that are non-static are used in the toString generation. You can exclude fields by specifying them in the exclude parameter. You can also explicitly specify the fields that are to be used by specifying them in the of parameter.

Array fields are handled by way of Arrays.deepToString(Object[]) where necessary. The downside is that arrays with circular references (arrays that contain themselves, possibly indirectly) results in calls to toString throwing a StackOverflowError. However, the implementations for java's own ArrayList suffer from the same flaw.

The toString method that is generated will print the class name as well as each field (both the name and the value). You can optionally choose to suppress the printing of the field name, by setting the includeFieldNames flag to false.

You can also choose to include the result of toString in your class's superclass by setting the callSuper to true.


Optional Element Summary
 boolean callSuper
          Include the result of the superclass's implementation of toString in the output.
 boolean doNotUseGetters
          Normally, if getters are available, those are called.
 String[] exclude
          Any fields listed here will not be printed in the generated toString implementation.
 boolean includeFieldNames
          Include the name of each field when printing it.
 String[] of
          If present, explicitly lists the fields that are to be printed.
 

includeFieldNames

public abstract boolean includeFieldNames
Include the name of each field when printing it. default: true

Default:
true

exclude

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

Default:
{}

of

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

Mutually exclusive with exclude().

Default:
{}

callSuper

public abstract boolean callSuper
Include the result of the superclass's implementation of toString in the output. default: false

Default:
false

doNotUseGetters

public abstract 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

Default:
false

Lombok - v0.10.8

Copyright © 2009-2011 The Project Lombok Authors, licensed under the MIT licence.