package test;
import java.util.*;class t1{
public void f3(ArrayList out){
ArrayList in= new ArrayList();
in.add("123");
out=in;
out.set(0, "123");
}
}
public class testInt {
public static void main(String[] args){
ArrayList list=new ArrayList();
list.add("456");
t1 t =new t1();
t.f3(list);
System.out.println(list.get(0));
}
}
import java.util.*;class t1{
public void f3(ArrayList out){
ArrayList in= new ArrayList();
in.add("123");
out=in;
out.set(0, "123");
}
}
public class testInt {
public static void main(String[] args){
ArrayList list=new ArrayList();
list.add("456");
t1 t =new t1();
t.f3(list);
System.out.println(list.get(0));
}
}
public void f3(ArrayList out){
ArrayList in= new ArrayList();
in.add("123");
out=in; //将上面三行注释掉输出 123
//原因是 out现在指向新建的 in LIST
out.set(0, "123");
}
}
public class testInt {
public static void main(String[] args){
ArrayList list=new ArrayList();
list.add("456");
t1 t =new t1();
t.f3(list);
System.out.println(list.get(0));
}
}
不过看看http://www.javaeye.com/topic/12961,我明白了些
in.add("123");
out=in; // 这句是 把 in 的地址 付给out ,已经不是传递过来的 out 的地址了
out.set(0, "123"); //因此 这里根本没有 更改传递 过来的参数 out 的内容
t.f3(list); //因此这句 对 list 没有产生任何的变化
System.out.println(list.get(0));