结合下图理解Java的值传递和引用传递的方式
附上测试代码:
public class Test {
String str = new String("hello");
String str2 = new String("hello2");
char[] ch = {'a', 'b'};
public static void main(String[] args) {
Test test = new Test();
test.change(test.str, test.ch);
test.change2(test.str2);
System.out.println("str=" + test.str);
System.out.println("str2=" + test.str2);
System.out.println(test.ch);
}
public void change(String str_temp, char ch_temp[]) {
str_temp = "test ok";
ch_temp[0] = 'c';
}
public void change2(String str2_temp) {
str2_temp = "test ok2";
}
}