With reference to Why i am getting type mismatch: cannot convert from int to byte, I tried a quick search in the JLS to find where is it mentioned that the result of an addition between byte
operands is automatically widened to int
.
The best I found was this tutorial, but I didnt' find anything in the JLS.
The Conversions chapter does not mention anything about the addition operator, at least I couldn't find something. The Additive Operators paragraph does not mention automatic widening of byte. It mentions that the type of each of the operands of the binary - operator must be a type that is convertible (§5.1.8) to a primitive numeric type
, but nothing about widening. And byte is a numeric data type.
What am I missing?
You were almost there, it is in 15.18.2:
Binary numeric promotion is performed on the operands (§5.6.2).