an unboxing conversion (§5.1.8) optionally followed by a widening primitive
conversion.
If, after the conversions listed above have been applied, the resulting type is a raw
type (§4.8), an unchecked conversion (§5.1.9) may then be applied.
In addition, if the expression is a constant expression (§15.28) of type byte, short,
char, or int:
• A narrowing primitive conversion may be used if the type of the variable is byte,
short, or char, and the value of the constant expression is representable in the
type of the variable.
• A narrowing primitive conversion followed by a boxing conversion may be used
if the type of the variable is:
– Byte and the value of the constant expression is representable in the type byte.
– Short and the value of the constant expression is representable in the type
short.
– Character and the value of the constant expression is representable in the type
char.
The compile-time narrowing of constant expressions means that code such as:
byte theAnswer = 42;
is allowed. Without the narrowing, the fact that the integer literal 42 has type int would
mean that a cast to byte would be required:
byte theAnswer = (byte)42; // cast is permitted but not required
Finally, a value of the null type (the null reference is the only such value) may be
assigned to any reference type, resulting in a null reference of that type.
It is a compile-time error if the chain of conversions contains two parameterized
types that are not in the subtype relation (§4.10).