Map uses "=" to assign values in the method body

clipboard.png

as shown in the figure, I define a map1, in main and a map2,map2 in which the content is {"test": "test"}, and then I assign map2 to map1, in the transform method, and finally I output map1. in main. But the result is {}, that is, its value is still empty after an assignment in transform.

Why is this? All I know is that it has something to do with the stack, but the detailed reason is a little vague. I wonder if anyone can explain it in detail.

Mar.10,2021

because the assignment is assigned to the map1 in transform, you print the map1
in main. These two have nothing to do with each other except for the same name

.

there are four variables
map1 in main, map1 in map2
transform, and map2

after passing parameters, the map1 of main and the map1 of transform point to the same Map
map1 = map2. After
transform, the map1 points to Map
main of map2 or to the original address

.

it is recommended that you take a look at the value passing and reference passing of java http://www.cnblogs.com/wang-m.. You can't explain it clearly

.
Menu