Inspectopedia Help

'instanceof' with incompatible interface

Reports instanceof expressions where the compared type is an interface, and the compared expression has a class type that neither implements the compared interface, nor has any visible subclasses which implement the compared interface.

Although that might be intended, normally such a construct is most likely an error, where the resulting instanceof expression always evaluates to false.


interface I1 {} interface I2 {} interface I3 extends I1 {} static class Sub1 implements I1 {} static class Sub2 extends Sub1 implements I2 { void test(Sub1 sub1) { if (sub1 instanceof I3) { // here 'I3' is incompatible interface } } }

Inspection Details

Available in:

IntelliJ IDEA 2023.3, Qodana for JVM 2023.3


Java, 233.SNAPSHOT

Last modified: 13 July 2023