Outcast Downcasting
suggest changeBeware of using “downcasting” - Downcasting is casting down the inheritance hierarchy from a base class to a subclass (i.e. opposite of polymorphism). In general, use polymorphism & overriding instead of instanceof & downcasting.
C++ Example
// explicit type case required
Child *pChild = (Child *) &parent;
Java Example
if(mySubClass instanceof SubClass) {
SubClass mySubClass = (SubClass)someBaseClass;
mySubClass.nonInheritedMethod();
}
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents