标签:
Java中只有按值传递,没有按引用传递!
public static void main(String[] args) { String x = new String("ab"); change(x); System.out.println(x); } public static void change(String x) { x = "cd"; }
ab
解决办法:
public static void main(String[] args) { StringBuilder x = new StringBuilder("ab"); change(x); System.out.println(x); } public static void change(StringBuilder x) { x.delete(0, 2).append("cd"); }
cd
标签:
原文地址:http://www.cnblogs.com/lnas01/p/5352207.html