首页 > 解决方案 > 输出:无错误您可能分配了太多内存任何人都可以详细解释

问题描述

查看下面的源代码

class Test
{
    public static void main(String[] args)
    {
        Double object = new Double("2.4");
        int a = object.intValue();
        byte b = object.byteValue();
        float d = object.floatValue();
        double c = object.doubleValue();

        System.out.println(a + b + c + d );

    }
}

输出:无错误您可能分配了太多内存

谁能详细解释

标签: java

解决方案


将您的代码更改为

Double object = new Double("2.4");
int a = object.intValue();
byte b = object.byteValue();
float d = object.floatValue();
double c = object.doubleValue();

System.out.println(a);        
System.out.println(a + b);        
System.out.println(a + b + c);        
System.out.println(a + b + c + d );   

并探索


推荐阅读