Skip to content

instanceof

Instanceof vs. polimorphism

An instanceof check is often an indication for misplaced source code. Some developer say that instanceof checks are ugly code, but there are reasons against instancof checks beyond a subjective feeling. In this blog I want to compare instanceof checks with polymorphism and discuss the downsides. This blog is intended to be used as a basis for desing decisions and discussions about code design. Instanceof motivations Everytime we write an instanceof check in java we are interessted in the capabilities of an object. We want to know if an object has specific features or methods or if it has not. This can also be implicit features that are derived from the type. In this case we have 2 options: Introduce… Read More »Instanceof vs. polimorphism

GDPR Cookie Consent with Real Cookie Banner