不知道你前面的意思,:(
不过参数的传递都是传递对象的引用
所以你内部改变外部也应该改变,除非你中途变换成了另一个对象
最后是ia=null的话,ia.append的使用是非法的,有Exception的
或者编译不通过,提醒你没有初始化

解决方案 »

  1.   

    楼上的,不会呀。你试试把:
    ia.append(" ok?");改成ia=null;试试。看看两次的结果 有什么不同?
      

  2.   

    为什么ia=null;的时候,外部的stringbuffer a;还是原来的值?而用ia.append("ok")的时候外部的stringbuffer a也跟着改变呢?
      

  3.   

    JAVA一律传句柄 也就是传地址
    当然会改变如果要传值,使用Class.clone()
      

  4.   

    to: warmworm(warmworm)那为啥ia=null, 的时候ia 指向的外部的a为啥不改变呢?按你说的,外部的a 也应该改变成null才对呀。
      

  5.   

    to:Remus(十年):
    看来,传值与传址你还有点不清
    ia 是一个引用(a)的副本
    他与a指向同一个对象
    故若你用ia.append("ok?") 是对对象的操作
    但你用ia=null,是对这个引用值的操作。不会影响原对象。
      

  6.   

    to:dentance(登徒子) :)我确实是对这两个概念非常的迷惑,那您能告诉我,在把对像做为参数传给方法的时候,哪个是对像的引用,哪个是对像引用的副本,传递给方法的时候是传的副本的值?还是址?
    根据上述现象,我理解的是ia.append()是传址,ia=null是传值,对吗?这样一来我又迷糊了。。:(
      

  7.   

    刚看了一遍java in a nutshell..明白了一点。ia=null是一个空引用。也就是不对任何对象进行引用,所以也就不会对原始值产生影响。。:)
      

  8.   

    Point q = new Point(3.0, 4.5);  // A point with an X coordinate of 3
    changeReference(q);  // Prints 3,2,1 and modifies the Point
    System.out.println(q.x);  // The X coordinate of q is now 0!
    When the changeReference() method is invoked, it is passed a copy of the reference held in variable q. Now both the variable q and the method parameter p hold references to the same object. The method can use its reference to change the contents of the object. Note, however, that it cannot change the contents of the variable q. In other words, the method can change the Point object beyond recognition, but it cannot change the fact that the variable q refers to that object. 
      

  9.   

    ia.append(" ok?");的作用是在當前對象後加上append(string str)里的str的值