Casting to incompatible interface
Reports type cast expressions where the cast type is an interface and the cast expression has a class type that neither implements the cast interface, nor has any visible subclasses that implement the cast interface.
Although this might be intended, such a construct is most likely an error, and will result in a java.lang.ClassCastException
at runtime.
Example:
interface A {}
interface Z {}
static class C {}
void x(C c) {
if (c instanceof Z) {
A a = ((A)c); // cast to incompatible interface 'A'
}
}
Inspection Details | |
---|---|
Available in: | IntelliJ IDEA 2023.3, Qodana for JVM 2023.3 |
Plugin: | Java, 233.SNAPSHOT |
Last modified: 13 July 2023