java 小程序分析:参数传递
public class Test{ public static void main (String [] ABC){ StringBuffer a = new StringBuffer("A"); StringBuffer b = new StringBuffer("B"); operate(a,b); System.out.println(a+","+b); } public static void operate (StringBuffer x,StringBuffer y){ x.append(y); y=x; } }
输出:AB,B
x.append(y)使a为“AB”
而y=x语句没有改变b的内容,java的参数传递是传值。