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。

要回复问题请先登录注册