Why does byte to char conversion needs an int widening conversion

307 Views Asked by At

According to the specification

The following conversion combines both widening and narrowing primitive conversions:

byte to char

First, the byte is converted to an int via widening primitive conversion (§5.1.2), and then the resulting int is converted to a char by narrowing primitive conversion (§5.1.3).

Widening conversion of a byte literal to an int does not change the literal. It compulsorily extends the bits but doesn't change the value or the literal. So what's the point in here? JVM could have directly converted a byte literal to a char literal (of course by providing the casting instruction) instead of converting a byte to int and then converting it to char which also requires a casting instruction?

0

There are 0 best solutions below