Consider the following code:
short x = 1;
x += 1; // all good
x = x + 1; // error, since (x + 1) returns int
The question is:
Is it safe to say that internally Java automatically cast x
to int
, then back to short
? Something like this:
x += 1 will be expand to x = (short) ((int) x + 1);
The same question about the rest of the assignment operators: += -= *= /= %= &= ^= |= <<= >>= >>>=