Java op= 运算符

来源:互联网 发布:魏氏熏鸡淘宝网 编辑:程序博客网 时间:2024/05/17 23:45

E1 op= E2 形式的复合运算表达式等价于 E1 = (T)((E1) op (E2)), 其中T是E1的类型。

例如:

short x = 3;x += 4.6;
结果是7,等价于
short x = 3;x = (short)(x + 4.6);
byte b = 10;b *= 5.7;System.out.println(b); // prints 57

byte b = 100;b /= 2.5;System.out.println(b); // prints 40


char ch = '0';ch *= 1.1;System.out.println(ch); // prints '4'


char ch = 'A';ch *= 1.5;System.out.println(ch); // prints 'a'
更详细的说明可以参考
http://docs.oracle.com/javase/specs/jls/se5.0/html/expressions.html#15.26.2

0 0
原创粉丝点击