Should you ever do explicit casts in modern Java?
The more the merrier
11%
Only exceptional cases
56%
Never!
22%
Idk
11%
9 votes · Closed
I feel like it's a big red flag, but I'm not sure it'd be safe to reject any code that has explicit type casting (throught e.g. linting + commit checks).
if (generalObject instanceof SpecificObject) {
SpecificObject myObj = (SpecificObject) generalObject
}
No need to consider legacy code or badly written dependencies. Let's say we control all of the code.