Passing by reference in Java?

后端 未结 4 1366
Happy的楠姐
Happy的楠姐 2020-12-20 22:19

In C++, if you need to have 2 objects modified, you can pass by reference. How do you accomplish this in java? Assume the 2 objects are primitive types such as int.

4条回答
  •  执念已碎
    2020-12-20 22:55

    You can't. Java doesn't support passing references to variables. Everything is passed by value.

    Of course, when a reference to an object is passed by value, it'll point to the same object, but this is not calling by reference.

提交回复
热议问题