Warning equals/hashCode on @Data annotation lombok with inheritance

后端 未结 4 460
轻奢々
轻奢々 2020-12-23 03:01

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

4条回答
  •  没有蜡笔的小新
    2020-12-23 03:31

    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.

提交回复
热议问题