instanceof or getClass() == SomeClass.class where the
expression checked is this. Such expressions
are indicative of a failure of object-oriented design, and should be replaced by
polymorphic constructions.
Example:
class Super {
void process() {
if (this instanceof Sub) { // warning
doSomething();
} else {
doSomethingElse();
}
}
}
class Sub {}
To fix the problem, the method overriding should be used:
class Super {
void process() {
doSomethingElse();
}
}
class Sub {
@Override
void process() {
doSomething();
}
}