class Ref{
String temp = "Hello";
}
public class StringProblem {
public static void main(String[] args) {
String str1 = "hello";
System.out.println(str1);//输出"hello"
change(str1);
System.out.println(str1);//输出"hello"
Ref ref = new Ref();
System.out.println(ref.temp);//输出"Hello"
change(ref);
System.out.println(ref.temp);//输出"world"
}
public static void change (String str ){
str = "world";
}
public static void change (Ref str ){
str.temp = "world";
}
}
为什么str1的值不会修改 ref.temp的值会修改?