好吧,我承认,实参形参、传值引用什么的真是把我绕晕了. You do speak Chinese!
Java 只有传值好不好,看图:
public class TestString{
public static void testStr(String x){
x = "word"; //由虚线箭头1变为的实线箭头2
}
public static void main(String[] args) {
String a = "hello" ;
TestString.testStr(a);
System.out.println("a = " + a);
}
}
输出: a = hello
2.
public class TestStringBuffer {
public static void testStrBuf(StringBuffer x, StringBuffer y){
x.append(y);
y = x;
}
public static void main(String[]args) {
StringBuffer a = new StringBuffer("A");
StringBuffer b = new StringBuffer("B");
TestStringBuffer.testStrBuf(a,b);
System.out.println(a + " " + b);
}
}
输出: AB B