[Java] Lombok usage can be simplified


I have a suggestion for a new rule.
Lombok provides a convenience annotation @Data which is a shortcut for
@ToString , @EqualsAndHashCode , @Getter, @Setter, and @RequiredArgsConstructor.

Noncompliant Code

@RequiredArgsConstructor // Non-compliant, can be simplified
class Foo {
  // ...


@Data // Compliant
class Foo {
  // ...
  • type : Code Smell
  • Tags: java, lombok, clumsy


It might also make sense to suggest @Data even when only @Getter, @Setter and @RequiredArgsConstructor are used, however, this is not exactly equivalent since @EqualsAndHashCode and @ToString would be added.

I would add that @Value is shorthand for:
final @ToString @EqualsAndHashCode @AllArgsConstructor @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) @Getter
Lombok docs

1 Like