Does not compile.
Important is the plus sign.
As the language specification says (
5.6.2 Binary Numeric Promotion),
binary numeric promotion occurs on these operands:
the multiplicative operators *, / and % (�15.17)
The addition and subtraction operators for numeric types + and - (�15.18.2)
The numerical comparison operators <, <=, >, and >= (�15.20.1)
The numerical equality operators == and != (�15.21.1)
The integer bitwise operators &, ^, and | (�15.22.1)
In certain cases, the conditional operator ? : (�15.25)
And in binary numeric promotion the following happens:
If any of the operands is of a reference type, unboxing conversion (�5.1.8) is performed. Then:
If either operand is of type double, the other is converted to double.
Otherwise, if either operand is of type float, the other is converted to float.
Otherwise, if either operand is of type long, the other is converted to long.
Otherwise, both operands are converted to type int.
So in the above example, the last thing occurs, both operands are converted to an int.
The result of the addition is an int, and you want to store it into a byte, this is a narrowing primitive conversion. It is also an assignment conversion as you store the value of an exprssion (b1 + b2

into a variable.
Language specification says in
5.2 Assignment Conversion:
... narrowing primitive conversion may be used if all of the following conditions are satisfied:
1) The expression is a constant expression of type byte, short, char or int.
2) The type of the variable is byte, short, or char.
3) The value of the expression (which is known at compile time, because it is a constant expression) is representable in the type of the variable.
If the type of the expression cannot be converted to the type of the variable by a conversion permitted in an assignment context, then a compile-time error occurs.
2) and 3) are ok, but 1): The variable b3 is NOT a constant (is not final), so a compile error occurs.
Why is it not a compile time error in the 3rd case?
The result of the expression i1 + i2; is an int.
This int is stored into int-variable i3. So there is no narrowing conversion, and the three cases above are not checked.
Yours,
Bu.