Junior — Middle
What is the function of the @Data annotation in the Lombok library, and how is it useful in development?
sobes.tech AI
Answer from AI
The @Data annotation from the Lombok library automatically generates the following methods for a class: getters and setters for all fields, toString(), equals(), and hashCode() methods, as well as a default constructor. This significantly reduces boilerplate code, improving readability and ease of maintenance.
Example usage:
import lombok.Data;
@Data
public class User {
private String name;
private int age;
}
In this example, there is no need to manually write getters, setters, and other methods — Lombok will generate them automatically during compilation.