Weirdness in Equated Java Arrays: References vs. Pointers

后端 未结 4 1530
囚心锁ツ
囚心锁ツ 2020-12-11 21:48

Having a problem understanding what\'s going on n the code below. The behavior of arrays c and d is what I would expect. But what\'s going on with

4条回答
  •  佛祖请我去吃肉
    2020-12-11 22:04

    The array initializer is calling new under the hood (so in this case it's syntactic saccharine). Your swap nearer the top is just swapping references, the one below is performing exactly how you'd expect a reference to perform.

    The linked article refers to parameters... In Java all parameters are by value, it's just that references themselves get passed by value i.e. changes to the REFERENCE (not its dereferenced content) won't be reflected outside the scope of the subroutine.

提交回复
热议问题