首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

java += 原理解决思路

2012-05-12 
java + 原理有哪位仁兄知道java 中 + 的底层原理吗, 比如类型转换之类等 小弟对原理比较入迷[解决办法]

java += 原理
有哪位仁兄知道java 中 += 的底层原理吗, 比如类型转换之类等 小弟对原理比较入迷

[解决办法]
不需要理解的太复杂吧?基本上就是自动帮你加个强转而已。

比如:
i += expRight;
约等于
i = (int) (i + expRight);
[解决办法]

Java code
from:java language specification15.26.2 Compound Assignment OperatorsA 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.For example, the following code is correct:    short x = 3;    x += 4.6;and results in x having the value 7 because it is equivalent to:    short x = 3;    x = (short)(x + 4.6); 

热点排行
Bad Request.