[OCP 21 book] | [OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Jeanne Boyarsky wrote:You aren't allowed to change the "thing in memory" that the variable points to directly. For an int, that's the value. For an array, it's a reference to a bunch of array elements.
This example would be equivalent to the int one:
Changing the array to point to a different array would not affect the caller. Just like changing the int to a different number doesn't change the caller.
By contrast, in your example, the array is still the same array. Just with different values for the elements.
[OCP 21 book] | [OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
I think there is nothing wrong with this statement.Rico Felix wrote:Objects are passed by reference...
Jeanne Boyarsky wrote:In your example, there are two double arrays: tempature and other. The former is not actually used anywhere. You could delete it and the code would do the same thing. The other is passed to both methods. Where is modified, but still the same array.
In my example, I actually create a new array and change the reference in the method. The caller doesn't know about this change since it still points to the original array.
That is total nonsense, even though you see it in many places.Rico Felix wrote: . . .
Primitives are passed by value... Objects are passed by reference...
. . .
There is a lot wrong with that statement.Tapas Chand wrote:
I think there is nothing wrong with this statement.Rico Felix wrote:Objects are passed by reference...
That bit is correct, but the rest of your post was incorrect. Do not prefer pointer to reference. You cannot manipulate the pointer behind the reference.
Object references(pointers) are passed by value . . .
Campbell Ritchie wrote:...Do not prefer pointer to reference...
Yes, it is that misleading. And it is often caused by using the terminology wrongly.Liutauras Vilda wrote:. . . Maybe not that misleading, but not fully explained in deep details. And this confusion could take a place by using terminology interchangeably in different programming languages.
. . .