如何解决Findbugs SIO_SUPERFLUOUS_INSTANCEOF
|| 在我的findbugs报告中,以下代码部分中有SIO_SUPERFLUOUS_INSTANCEOF正确性错误/** Allow Comparison based on User-Labels */
public int compareTo(AbstractListItem o) {
if ( !( o instanceof AbstractListItem ) ) {
// Correctness - Unnecessary type check done using instanceof operator
// : Method com.x.y.gui.topology.TopologyListNode.compareTo (AbstractListItem)
// does an unnecessary type check using instanceof operator when it
// can be determined statically
return -1;
}
静态确定类型的正确方法是什么?解决方法
public int compareTo(AbstractListItem o)
-o
是AbstractListItem
,您无需检查。
如果您有public int compareTo(Object o)
,则需要instanceof
,并且不会发出警告。,在您的代码中,对象o的类型已经静态确定为AbstractListItem,因此instanceof是不必要的。 Findbugs将其报告为警告,因为它可能是错误的标志,例如,您要检查的是AbstractListItem的子类型,但是您错误地键入了AbstractListItem。版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。