In my findbugs report I have a SIO_SUPERFLUOUS_INSTANCEOF correctness error in the following code section
/** 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;
}
What is the correct way to statically determine the type?
public int compareTo(AbstractListItem o)–ois anAbstractListItem, you don’t need to check.If you had
public int compareTo(Object o)then yourinstanceofwould be needed and not produce a warning.