Downcast is a term used to describe a data type conversion that goes from a more general type to a more specific one, like going from a base class reference to a derived class reference. It's the opposite of an upcast, and is generally considered a code smell since it often indicates a flaw in the class hierarchy design.
Did you see that gnarly downcast in the new intern's Java code? I swear these kids come out of school writing the most convoluted class hierarchies just to show off their "object-oriented skills".
I was in a code review yesterday and saw a downcast that made me want to flip the table and rage quit on the spot. Sometimes I wonder why we even bother with inheritance when it seems to cause more problems than it solves.
Downcasting and Upcasting in Java - This article dives into the nitty gritty details of downcasting and upcasting in Java, for those times when you absolutely must use them (but probably shouldn't).
Inheritance vs. Composition - A thought-provoking piece on when to favor composition over inheritance to avoid getting yourself into downcast hell in the first place.
Refactoring Away from Downcasting - Some sage advice from the OG of refactoring, Martin Fowler himself, on how to refactor your way out of a downcast-infested codebase. Worth a read before your next inheritance misadventure.
Note: the Developer Dictionary is in Beta. Please direct feedback to skye@statsig.com.