传递引用

代码如下:

package ClassDemo; public class TestPassByReferece {
public static void main (String[] args) {
test01();
StringBuilder sb = new StringBuilder("eclipse");
System.out.println(sb);
changeSb02(sb);
System.out.println(sb);
}
private static void test01() {
int num = 10;
String str = "hello";
num = 20;
str = "java";
System.out.println("Before changeStr: " + str);
changeStr(str);
System.out.println("After changeStr: " + str);
}
public static void changeStr(String text) {
System.out.println("text before: " + text);
text += " windows";
System.out.println("text after: " + text);
} public static void changeSb(StringBuilder builder) {
builder.delete(0, builder.length()).append("10");
}
public static void changeSb02(StringBuilder builder) {
builder = new StringBuilder("ipad");
}
}

只相信苦尽甘来
原文地址:https://www.cnblogs.com/F001li/p/7055665.html