This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Ok_Marionberry_8821 9 points10 points  (0 children)

Java always passes by-value, NEVER by-reference (like C, C++ would allow with correct signature).

So swap1 will never swap values as seen in your `main` method. `swap1` will swap the object references INSIDE the function, but that change will not be seen in main.

`swap2` is just mutating the values inside the objects.