美文网首页
使用 Lombok, spotbugs 报 Class inhe

使用 Lombok, spotbugs 报 Class inhe

作者: BitterOutsider | 来源:发表于2021-03-09 08:51 被阅读0次

报错信息如下

Class inherits equals() and uses Object.hashCode()(https://spotbugs.readthedocs.io/en/latest/bugDescriptions.html#HE_INHERITS_EQUALS_USE_HASHCODE)

This class inherits `equals(Object)` from an abstract superclass, and `hashCode()` from `java.lang.Object` (which returns the identity hash code, an arbitrary value assigned to the object by the VM).  Therefore, the class is very likely to violate the invariant that equal objects must have equal hashcodes.

If you don't want to define a hashCode method, and/or don't believe the object will ever be put into a HashMap/Hashtable, define the `hashCode()` method to throw `UnsupportedOperationException`.

**Bug kind and pattern: HE - HE_INHERITS_EQUALS_USE_HASHCODE**

解决方案
在类上面添加注解 @EqualsAndHashCode(callSuper = true)

相关文章

网友评论

      本文标题:使用 Lombok, spotbugs 报 Class inhe

      本文链接:https://www.haomeiwen.com/subject/rrsvqltx.html