Java / Lombok Interview questions
What is @ToString used for?
@ToString generates a toString() override that prints the class name followed by
each field's name and value, giving a readable default representation instead of Java's default
ClassName@hashcode output.
@ToString public class Person { private String name; private int age; } // toString() produces: "Person(name=Ada, age=34)"
By default it includes every field, but individual fields can be excluded with
@ToString.Exclude — commonly used for sensitive fields (passwords, tokens) that shouldn't
end up in logs, or for fields that would make the output unreasonably large or cause infinite recursion (like
a reference back to a parent object).
More Related questions...