This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I "know" that Java always passes by value, but I want to verify my understanding of what this means. Consider the following code snippet.
In the above code, an instance of A is created and a reference to that instance is assigned to the variable a1. Then a copy of that reference (that is, a value) is passed to the method changer, where it's assigned to a local variable a2. Now, a2 is pointing to the same object as a1, so the actual object can be modified from within the method.
But here's the distinction: When a2 is assigned to null, this has no effect on a1 because the reference originally assigned to a2 was only a copy (a value). On the other hand, if Java were actually pass by reference, then instead of a copy of the reference, a2 would have held the reference itself, and changing it to null would have also changed a1 to a null reference.
Is this accurate?
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer sscce.org