For example unboxing Integer results in a cast to Integer followed by a call to intValue(). Why not simply cast to Number followed by the necessary intValue() to get the primitive ? Naturally the question extends to unboxing all the other wrappers.
Share
If Java did what you propose, that would break the very important feature that boxing/unboxing causes no precision loss. There is already an established principle in Java that any precision-losing conversion must be explicitly asked for with a cast operator. It is illegal to write
so it would be wrong if this worked: