I have a entity which inherits from other. On other hand, I'm using lombok project to reduce boilerplate code, so I put @Data
annotation. The annotation @Data
with inheritance produces the next warning:
Generating equals/hashCode implementation but without a call to superclass, even though this class does not extend java.lang.Object. If this is intentional, add
@EqualsAndHashCode(callSuper=false)
to your type.
Is it advisable to add annotation @EqualsAndHashCode (callSuper = true)
or @EqualsAndHashCode (callSuper = false)
? If it is not added, Which one is it callSuper=false
or callSuper=true
?
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.