public class TestChar{
public static void main(String[] args){
int i=5;
char c='d';
c=c+(char)i;//编译不通过 <SPAN style="COLOR: #ff0000">//java中两个低级相互运算,其结果为能包含它的最小primitive,这里是结果是int</SPAN>
c='d'+(char)i;//编译通过
c+=(char)i;//编译通过 <SPAN style="COLOR: #ff0000">//这里+=运算会进行自动转化的</SPAN>
c='d'+11//编译通过
c=c+11;//编译不通过<SPAN style="COLOR: #ff0000">这里11默认的类型为int,char+int结果当然应该是int</SPAN>
c+=11;//编译通过 <SPAN style="COLOR: #ff0000">//+=运算自动转化</SPAN>
c=c+'d';//编译不通过 <SPAN style="COLOR: #ff0000">//java中两个低级相互运算,其结果为能包含它的最小primitive,这里是结果是int</SPAN>
c+='d';//编译通过 <SPAN style="COLOR: #ff0000">//+=运算自动转化</SPAN>
System.out.println(c);
}
}