public class StringBufferTest
{
static void aMethod(StringBuffer sf1, StringBuffer sf2)
{
sf1.append(sf2);
sf2 = sf1;
}
public static void main(String[] args)
{
StringBuffer sf1 = new StringBuffer("A");
StringBuffer sf2 = new StringBuffer("B");
StringBufferTest.aMethod(sf1, sf2);
System.out.println(sf1 + ":" + sf2);
}
}
既然在函数里sf2=sf1了,那么sf1和sf2应该指向同一一个对象,那么打印出来的也应该是AB:AB,可为什么是AB:B呢?请大神指路! |