Downcast works in the case when we are dealing with an upcasted object. Upcasting:
int intValue = 10;
Object objValue = (Object) intvalue;
So now this objValue
variable can always be downcasted to int
because the object which was cast is an Integer
,
int oldIntValue = (Integer) objValue;
// can be done
but because objValue
is an Object it cannot be cast to String
because int
cannot be cast to String
.