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:

  1. Add the @Data annotation to the class.
  2. Lombok will automatically generate Getter and Setter methods for classes, based on the corresponding fields.
  3. Lombok also creates a toString method for printing the object’s string representation.
  4. Lombok will create an equals method and a hashCode method for comparing objects and generating hash codes.
  5. 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.

bannerAds