Is using the instanceof
keyword against the essence of object oriented programming
?
I mean is it a bad programming practice?
I read somewhere that us
Usage of instanceof
is discouraged when same effect can be achieved via virtual methods, like in example of thomson_matt.
However, it's necessary to use instanceof
in some circumstances. For example, when your code gets Object from external source, say, network or third-party API which returns Object
, and you must decide what is the type of this Object and act appropriately.