Question :
char x = 'a'; 
x += 3; // ok  
x = x + 3; // compile ti开发者_Python百科me error
Because x += 3 is equivalent to x = (char)(x+3),  while x + 3 is default to int operation, assign an int to char must cast.  
From the JLS specification : 15.26.2 ,  
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 is evaluated only once. Note that the implied cast to type T may be either an identity conversion (?.1.1) or a narrowing primitive conversion (?.1.3).
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论