关于 java 引用传递和值传递,你的知否? 为什么sun要这么 做
public class Test03 {
public static void main(String[] args) {
StringBuffer s = new StringBuffer("good");
StringBuffer s2 = new StringBuffer("bad");
test(s, s2); System.out.println(s);// 9 goodhah这里为什么是 goodhah System.out.println(s2);// 10 bad
但这里为什么是 bad
}
static void test(StringBuffer s, StringBuffer s2) { // 此
System.out.println("s="+s);// 1 good
System.out.println("s2="+s2);// 2 bad
s2 = s;// 3
s = new StringBuffer("new");// 4
System.out.println("s="+s);// 5 new
System.out.println("s2="+s2);// 6 good