/**
1、StringBuffer是引用类型
2、引用类型sbx传递时传递的变量在内存中的地址
*/
public class CoreJava03 {
public static void main(String[] args) {
//StringBuffer 是引用类型
StringBuffer sbx = new StringBuffer(“Hello”);
sbx.append(“World”);
//输出HelloWorld,是因为直接输出Hello+World
System.err.println(“1:”+sbx);
//sbx传递时传递的变量在内存中的地址
//输出HelloWorldNice,是因为在输出Hello+World的基础上又加上了Nice(也就是说调用了getStr方法里的Nice)
getStr(sbx);
System.err.println(“4:”+sbx);
}
public static void getStr(StringBuffer sbf){
//输出HelloWorld,是因为传的是内容(因为还没有加上Nice)
System.err.println(“2:”+sbf);
sbf.append(“Nice”);
//输出HelloWorldNice,(因为已经加上Nice)
System.err.println(“3:”+sbf);
}
}
一张图读懂
值传递、引用传递