(x = x + y) or (x + = y) – type cast differences
Faced such a property of addition. We have two variables:
int x = 1; long y = 2;
yneed to add to
x. If we use simple addition, the IDE will refuse to compile:
x = x + y; //Incopatible types
If we use the following construction:
x += y;
then the code is processed correctly.
The error is understandable – we are trying to cram
int, the IDE sees a potential error and does not allow to compile. But why does it happen in the second case?