我正在使用Java和新的它。奇怪的类型转换,同时做variableOfTypeA + = variableOfTypeB
当我尝试
int integerValue = 100;
long longValue = 100;
integerValue = integerValue + longValue;
我得到 “类型不匹配:不能从长到int转换”。
但
integerValue+=longValue;
工作正常,这意味着它是做演员对我来说:)
有什么事情 “+ =” 本身就具有?任何具体原因?
编辑:哎呀!太常见的问题! :)我应该先彻底搜索,我的坏!
http://stackoverflow.com/questions/8272635/why-does-java-perform-implicit-type-conversion-from-double-to-的重复整数当使用 – sw1nn 2012-03-13 14:37:49
可能重复的[可能会损失的行为精度](http://stackoverflow.com/questions/2696812/varying-behavior-for-possible-loss-of-precision) – 2012-03-13 14:50:31