Interesting observation on byte addition and assignment
问题 Today while helping someone I came across an interesting issue which I couldn't understand the reason. While using += we don't need to explicit casting, but when we use i+i, we need to explicitly cast. Couldn't find exact reason. Any input will be appreciated. public class Test{ byte c = 2; byte d = 5; public void test(String args[]) { c += 2; d = (byte) (d + 3); } } 回答1: Java is defined such that += and the other compound assignment operators automatically cast the result to the type of the