problemTo this day, I always thought: i + = j is equivalent to i = i + j; But suppose there is: int i = 5;long J = 8; i = i + j cannot compile, but i + = J can be compiled. This suggests that there is a difference between the two. Does this mean that i + = j, which is actually equivalent to i= (type of i) (i + j)?
Essence Answer:This question, in fact, has been answered in the official documentation.please look here. §15.26.2 Compound Assignment Operators. And then copy the official documentation. For compound assignment expressions, E1 op= E2 (such as i + = J;I-=J, etc.) are actually equivalent to E1 = (t) ((E1) op (E2)), where T is the type of the element E1. For example, the following code
Shortx= 3;x+= 4.6;
Equals
Shortx= 3;x= ( Short)(x+ 4.6);
StackOverflow Link Http://stackoverflow.com/questions/8710619/java-operator
Column Introduction:
very like StackOverflow, can always find a solution to the problem of incurable diseases. Accidentally found that the site has a list of heat. So select some of the more hot questions, read the answers to each question, and then sort them out according to your own understanding. Therefore, these articles are not true translation, but in accordance with their own understanding of a number of additions and deletions, polishing, hoping to put the above discussion, more streamlined and effective sharing to everyone.
if you want to reprint, please specify the original address
Http://blog.csdn.net/lizeyang
"StackOverflow Good question" Java + = operator Essence