Inspectopedia
 
2024.3

'instanceof' check for 'this'

Warning
New
Last modified: 03 December 2024

Reports usages of instanceof or getClass() == SomeClass.class in which a this expression is checked.

Such expressions indicate a failure of the object-oriented design, and should be replaced by polymorphic constructions.

Example:

To fix the problem, use an overriding method: