Consider this code:
byte b=1;
long l=1000;
b += l;
I would expect the last statement to require an explicit cast because,
b+=l is evaluated as b = b+l and
(b+l) part gives an integer.
Integer cannot be assigned to byte without an explicit cast?
Well to start with,
b+lgives along, not anint…… but compound assignment operators have other behaviour. As per JLS section 15.26.2:
Note the cast to
T.