Warning equals/hashCode on Lombok’s @Data annotation with inheritance

The default value is false. That is the one you get if you don’t specify it and ignore the warning.

Yes, it is recommended to add an @EqualsAndHashCode annotation on the @Data annotated classes that extend something else than Object. I cannot tell you if you need true or false, that depends on your class hierarchy, and will need to be examined on a case-by-case basis.

However, for a project or package, you can configure in lombok.config to call the super methods if it is not a direct subclass of Object.

lombok.equalsAndHashCode.callSuper = call

See the configuration system documentation on how this works, and the @EqualsEndHashCode documentation for the supported configuration keys.

Disclosure: I am a lombok developer.

Leave a Comment