public class Demo1 {
public static void main(String[] args) {
String s = "hello";
int a = 1;
Point p = new Point(1, 2);
Collection c = new ArrayList();
c.add(p);
test(s, a, p, c);
System.out.println("s:"+s);
System.out.println("a:"+a);
System.out.println("p:"+p);
System.out.println("c:"+c);
}
public static void test(String s,int a,Point p,Collection c){
a++;
s= s + "world";
p.setX(3);
p = new Point(4, 5);
c.clear();
c.add(p);
c = new ArrayList();
p.setX(7);
c.add(p);
}
}
运行结果及报错内容
s:hello
a:1
p:Point{x=3, y=2}
c:[Point{x=7, y=5}]
我的解答思路和尝试过的方法
为什么结果不是
s:helloworld
a:2
p:Point{x=7, y=5}
c:[Point{x=7, y=5}]