Detailed introduction to parameter transfer of functions in Java

Parameter transfer of function in Java

Summary:

1. When an object (reference of an object) is passed as a parameter, a reference (equivalent to a pointer) is passed. In other words, changes made to the parameters in the function will affect the original object. 2. When the basic type or the wrapper set of the basic type is passed as a parameter, the value is passed. In other words, the modification of parameters in the function will not affect the original variables. 3. When an array (array reference)) is passed as a parameter, it is a reference (equivalent to a pointer). In other words, the modification of parameters in the function will affect the original array. 4. When the string type (Reference) is passed as a parameter, it is a reference. Only when any modification is made to the string, a new string object will be generated, and the value of the original string object will not be modified. (however, the reference of the new object can be assigned to the original reference. In this way, the surface phenomenon is that the original object has changed. In fact, it has not changed, but the reference pointing to it points to the new object).

Operation results:

a=2,b=B a=2,b=B ---------------------- 711139030 711139030 226046678 226046678 HUHUALIANG huhualiang ---------------------- 8 9 ---------------------- 1 9 ---------------------- 10 1 2 3 10 1 2 3

Thank you for reading, hope to help you, thank you for your support to this site!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>