Actually conversion from byte
to char
requires both a widening and a narrowing conversion (one after the other). This is precisely what the Java language specification requires. In section 5.5:
Casting contexts allow the operand of a cast operator (§15.16) to be converted to the type explicitly named by the cast operator.
Casting contexts allow the use of one of:
(...)
- a widening and narrowing primitive conversion (§5.1.4)
The table from the book looks incorrect (I'm assuming the caption is supposed to be "Java narrowing conversions"). There is no narrowing conversion from byte
to char
. The actual widening and narrowing primitive conversions are listed in the JLS sections 5.1.2 and 5.1.3.
Note that char
can be converted to byte
by a narrowing conversion alone, but byte
cannot be converted to char
by a widening conversion alone. (And, to make things just that extra bit complicated, conversion between char
and short
is a narrowing conversion in both directions!).
To answer your question succintly: Yes, primitive conversion to char
is always a narrowing
conversion - but it may require a widening conversion to be performed first!.