我不明白这段代码,为什么我的字符串c
没有改变main
方法而是改变changeString
. 你能给我解释一下吗?
class MainClass {
public static void main(String[] args) {
String c = "lalala";
changeString(c);
System.out.println("str in main = "+c);
}
public static void changeString(String str) {
str = str + "CHANGE!!!";
System.out.println("str in changeString = "+str);
}
}
结果:
str in changeString = lalalaCHANGE!!!
str in main = lalala