java-parameter passing mechanism

The java parameter passing mechanism is all value passing.

Basic type parameter transfers are all data values.

The value passed into the method is the copied value.

Reference type parameters transfer address values.

If it is an array parameter transfer, then it is a reference transfer (essentially still a value transfer, but since the array value transfer is to transfer the memory address of the array, when the method receives the memory address, the memory address is modified to correspond to the same value).

After the called function modifies the array, since the address points to the same array, the original main function accesses the memory address again and finds that the heap memory array has been modified.

Guess you like

Origin blog.csdn.net/h2728677716/article/details/132652369