Project Lombok's class annotation, @ToString
, is used to automatically generate a toString()
method within the class it annotates.
For this class:
@ToString
public class SomeClass {
String field1="Field #1";
String field2="Field #2";
}
Invoking the generated toString()
method will produce this output:
SomeClass(field1="Field #1", field2="Field #2")
Optional elements of the annotation can be used to include or exclude specific fields, but what I want to know is...
Maybe something like:
@ToString(exclude="#classname")
public class SomeClass { ... }
To exclude a field annotate the respective field with @ToString. Exclude .
In the presence of any method named toString() in the class (regardless of the return type), Lombok does not generate its toString() method. Different versions of Lombok may change the output format from the generated method. In any case, we should avoid code that relies on parsing the toString() method output.
The @ToString annotation generates an implementation for the toString() method where the class name, along with each field in order — separated by commas — is printed. By default, the field names will be printed. Passing includeFieldNames=false to the annotation will print the field values but not the field names.
No. The @ToString
annotation does not have any option that would let you do that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With