What is the usage of @Data in Lombok?
In Lombok, @Data is an annotation used to automatically generate common methods for a class, such as @Getter, @Setter, @ToString, @EqualsAndHashCode, and @RequiredArgsConstructor.
Here is the specific usage:
- Add the @Data annotation to the class.
- Lombok will automatically generate Getter and Setter methods for classes, based on the corresponding fields.
- Lombok also creates a toString method for printing the object’s string representation.
- Lombok will create an equals method and a hashCode method for comparing objects and generating hash codes.
- If there are fields with the final or @NonNull annotation in the class, Lombok will also generate a constructor with these fields.
By using the @Data annotation, code can be simplified and development efficiency can be improved.