The test proves that the Java underlying data type parameter pass value is a reference pass but the value does not change. The object is a reference pass, and the value changes. Why? Find a passage to explain the problem. "For a string object, although a reference is passed when the argument is passed, the Java Virtual Machine makes a special processing of the string object inside the function-depending on the string object as constant (final), so the string object referenced by the incoming reference address can be modified directly, Instead, a copy is created to manipulate it, and the operation on it does not affect the original value. "Refer to Sun's official certification questions to string,long,double as an example. Test whether the basic data type parameter pass value is a reference pass or a value pass:
Public
Static
voidA1 () {String s =
NewString ("Hello");
modify1(s);System.
out. println (s); }
Public
Static
voidmodify1 (String s) {S + ="world!"; }
Public
Static
voidA2 () {Double d =
NewDouble ("1.0");
modify2(d);System.
out. println (d); }
Public
Static
voidmodify2 (Double d) {d = 2.0; }
Public
Static
void A3 () {Long d =
NewLong ("1");
modify3(d);System.
out. println (d); }
Public
Static
voidModify3 (Long d) {d = 2L; }
Public
Static
voidMain (string[] args) {
A1();
A2();
A3(); }
Verify the Java underlying data type parameter delivery method