Not exactly the + operator, but rather that all operands in an expression
are promoted to at least type int before the operation is done. The same
error occurs if you assign (long + byte) to an int.
Jim ... ...
BEE MBA PMP SCJP-6
Joined: Sep 12, 2009
@ Tayitu Betule
Thanks Sir, but i just want to add a bit correction
(byte) a+b would not work.
(byte) (a+b) would work !!!
Joined: Jan 09, 2008
Yes, because the casting operation takes precedence over the + operator. With
((byte) a + b), only a is cast to byte. Then both a and b are promoted to int before
the add. The result must be explecitly downcast to be considered a byte (or short).