UIOE - Unnecessary 'instanceof' Evaluations
Checks that the runtime type of the left-hand side expression is the same as the one specified on the right-hand side.
Wrong
void operation () {
Animal animal;
Elephant elephant;
if ( animal instanceof Animal ) {
doSomething1(animal);
}
if ( elephant instanceof Animal ) {
doSomething2(elephant);
}
}
}
class Animal {}
class Elephant extends Animal {}
Tip: Remove unnecessary checks
Right
void operation () {
Animal animal;
Elephant elephant;
doSomething1(animal);
doSomething2(elephant);
}
}
class Animal {}
class Elephant extends Animal {}