Integer x=new Integer(5);
  x=new Integer(x.intValue()+1

解决方案 »

  1.   

    难道非要借助new 才能改变对象的值,
    有没有更直接的办法?
      

  2.   

    Integer这中wrapper class一旦分配了值,是不能如你所想的,不能改变值
      

  3.   

    Java的这种做法令我很不习惯,
    C++被改得莫名其妙
      

  4.   

    public class HelloWorld
       {
          public static void test(Integer  x, Integer  y)
             {
                x=new Integer(x.intValue()+1);
                y=new Integer(y.intValue()+1);
             }
          public static void main(String args[])
             {
                System.out.println("HelloWorld");
                for (int i=0;i<args.length;i++)
                       System.out.println(args[i]);  
                Integer x=new Integer(5);
                Integer y=new Integer(8);
                test(x,y);
                System.out.println(x.intValue());
                System.out.println(y.intValue());
             }
       }
     结果为什么仍x=5,y=8?
      

  5.   

    // 上面为什么?
    应该:
    public class HelloWorld
       {
          public static int x,y;      public static void test()
             {
                x++;
                y++;
             }
          public static void main(String args[])
             {
                System.out.println("HelloWorld");
                for (int i=0;i<args.length;i++)
                       System.out.println(args[i]);  
                x=5;
                y=8;
                test();
                System.out.println(x);
                System.out.println(y);
             }
       }
     
      

  6.   

    java是按值传递,用基本类型的对象封装器无法改变原值!《java核心技术 卷I》134页有详述。
      

  7.   

    那象Integer这样的对象有何用途?