I have a tyo byte variable
byte a = 3; byte b = 4;
If I sum them up, the value of the sum will be integer.
byte z = a+b //error, left side is byte, right side is integer
Why a + b is int?
Because the Java Language Specification says so
Binary numeric promotion is performed on operands (Β§5.6.2).Please note that binary numerical advancement performs conversion of a set of values ββ(Clause 5.1.13) and can perform conversion for unpacking (Clause 5.1.8).The type of additive expression for numeric operands is the advanced type of its operands.
Binary numeric promotion is performed on operands (Β§5.6.2).
Please note that binary numerical advancement performs conversion of a set of values ββ(Clause 5.1.13) and can perform conversion for unpacking (Clause 5.1.8).
The type of additive expression for numeric operands is the advanced type of its operands.
and regarding numerical progress ,
(Β§5.1.2) , :[...]int.
(Β§5.1.2) , :
int
, byte int . , a int.
byte
byte z = (byte) (b + a);
/ .