程序中字符串对象str明明进入了method方法(d.method( str );),为什么值没有变化??
class Demo {
public void method (StringBuffer sb) {
sb.append("StringBuffer");
}
public void method (String str) {
str = str + "String";
}
public static void main (String[] args) {
String str = new String("java");
StringBuffer buffer = new StringBuffer("android");
Demo d = new Demo();
d.method( str );
System.out.println( str );
d.method( buffer );
System.out.println( buffer );
}
}
|
|