Public class Foo {
2. Public static void main (string [] ARGs ){
3. stringbuffer A = new stringbuffer ("A");
4. stringbuffer B = new stringbuffer ("B");
5. Operate (A, B );
6. system. Out. printin {A + "" + B };
7 .)
8. Static void operate (stringbuffer X, stringbuffer y ){
9. x. append (y );
10. Y = X;
11 .}
12 .}
Printed as AB B
Because: AB B
Variable A \ B \ x \ y stores references of the stringbuffer variable rather than a stringbuffer object. The parameter received by operate is only a reference of the stringbuffer object. therefore, it can be understood that X and a all point to the same object; B and Y also point to the same stringbuffer object, so X. append (y) will change the stringbuffer object that X and a refer to (Add "B"); while y = x only changes the variable Y to the stringbuffer object that is the same as X, the object originally referred to by Y does not change.
Therefore, stringbuffer is the address passed by reference transmission.
Although the string type is also an object, the final type is equivalent to passing the value.
The problem of stringbuffer passing as parameters