String 不可变 笔试题
程序员文章站
2023-12-22 22:18:40
...
public class Test {
public static void main(String[] args){
String str = "aa";
A a = new A();
System.out.println("str="+str);
System.out.println("a.str="+a.str);
}
public void transform(String str,A a){
str = "aaaaa" ;
a.change("bbbbb");
}
}
class A{
public String str = "bb";
public void change(String str){
this.str = str;
}
}
答案
str=aa
a.str=bbbbb