Pattern: Use of instanceof
Issue: -
Checks for use of the instanceof
operator. Prefer using polymorphism instead.
Use the ignoreTypeNames
property to configure ignored type names (the class name specified as the right-hand expression of the instanceof
). It defaults to ignoring instanceof
checks against exception classes.
By default, the rule does not analyze test files. This rule sets the default value of the doNotApplyToFilesMatching property to ignore file names ending in 'Test.groovy', 'Tests.groovy' or 'TestCase.groovy'.
Example of violations:
class SomeClass {
boolean isRunnable = this instanceof Runnable // violation
}