We know:
int i = 5;
long j = 7;
i = i + j cannot compile, but i + = j can compile and run, and the result is i = 12.
This is because:
i += j is equivalent to i = (int)(i+j);
The summary is: for compound assignment expressions, E1 op= E2 (such as i += j; i -= j, etc.) is actually equivalent to E1 = (T)((E1) op (E2)), where T is the type of the element E1.
This question has actually been answered in the official documentation. Official document address §15.26.2 Compound Assignment Operators
The above is a brief introduction to the difference between += and ++ operators introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message. The editor will reply you in time. Thank you very much for your support to the Wulin Network website!