- public static void show(StringBuffer s1, StringBuffer s2) {
- s1.append(s2); // s1 = "hellojava"
- System.out.println("S1---" + s1);
- s2 = s1; // s2 = s1 = "hellojava" && s2 不再是以前的 s2 了,以前的 s2 没变,返回 java
- System.out.println("S2---" + s2);
- s2.append(s1); // s1 == s2 , 等价于 s1 += s1; s1 = hellojavahellojava, s2 = hellojavahellojava
- System.out.println("S2---" + s2); // 再 && 这个 s2 不再是以前的 s2 了,以前的 s2 没变
- System.out.println("S1---" + s1);
- }
复制代码- public static void show(StringBuffer s1, StringBuffer s2) {
- s1.append(s2); // s1 = hellojava
- System.out.println("S1---" + s1);
- s1 = s2; // s1 = s2 = java && s1 不再是 s1 了,s1 返回 hellojava
- System.out.println("S2---" + s2);
- s2.append(s1); // s2 += s2; s2 = s1 = javajava
- System.out.println("S2---" + s2);
- System.out.println("S1---" + s1);
- }
复制代码 |