Tutorial: using Lombok to reduce boilerplate code in Java | Gualtiero Testa
Always specify the fields you want in @EqualsAndHashCode or, in another words, never use the default @EqualsAndHashCode behaviour (all fields). Very important if the class is a JPA entity, where generated ID field should not be used for equality. Always exclude heavy fields (collections, arrays) in @EqualsAndHashCode and @ToString unless it is really necessary. Use @NoArgsConstructor when an empty constructor is needed (like for XML conversions and in JavaBeans) Never use Lombok @Data. As mentioned before, with the @Data annotation we cannot specify the fields for @EqualsAndHashCode and @ToString (see previous suggestions).Read full article from Tutorial: using Lombok to reduce boilerplate code in Java | Gualtiero Testa
No comments:
Post a Comment