Home  >  Q&A  >  body text

java-ee - eclipse编译问题

在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

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

大家讲道理大家讲道理2737 days ago546

reply all(1)I'll reply

  • 阿神

    阿神2017-04-21 10:59:51

    += 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();

    reply
    0
  • Cancelreply