java-ee - eclipse编译问题
大家讲道理
大家讲道理 2017-04-21 10:57:51
0
1
576

在myeclipse6.0编译完全通过的代码,在myeclipse10却编译报错。使用的jdk都是自己安装的jdk6.0(不是eclipse自带的),编译级别都是6.0.
代码如下:
Long a = new Long(0);
a+=new Float("3.2");
在myeclipse10中提示的错误如下:
The operator += is undefined for the argument type(s) Long, float

谁知道是什么原因啊?谢谢了。

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(1)
阿神

+= This operator is defined for basic types. The a and newFloat("3.2") you have here are both objects, so they cannot be calculated. Moreover, the classes under these two Number packages do not provide operation methods. If you want to do +3.2 operation on a, you need to:

Long a = new Long(0);
Float f = new Float("3.2");
long result = a.longValue() + f.longValue();
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template