Today in GitHub saw an open source project, which is in the collation and translation StackOverflow on the hot questions, the first question is in the discussion i = j is equal to I = i + j; The conclusion is not equal to. The argument is as follows:
if int i = 9; Long j = 11; Then i = i + j cannot compile, but i = j can compile. The description i + j is actually equivalent to i= (type of i) (i + j);
Refer to Official document: http://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.26.2
Document content:
A compound assignment expression of the form E1 op= E2 is equivalent to E1 = (T) ((E1) op (E2)), where T is the type of E1 , except that E1 are evaluated only once.
For example, the following code is correct:
Short x = 3;
x + 4.6;
and results in X has the value 7 because it is equivalent to:
Short x = 3;
x = (short) (x + 4.6);
For a compound assignment expression, the E1 op= E2 (such as I = J, I-J, and so on) is actually equivalent to E1 = (t) (E1) op (E2), where T is the type of E1 element.
StackOverflow Link Http://stackoverflow.com/questions/8710619/java-operator
The original git address is: https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/java-operator.md
A C