| Author |
Parameter Use
|
Bill Gorder
Bartender
Joined: Mar 07, 2010
Posts: 1282
|
|
I am studying for the SCJP. Please take the following code snippet.
Now I have no problem with lines I have commented, as it makes sense to me. What does not make sense to me is why d[0]++ or c[0]++ works.
c[0]++ --> seems to me this changes the value of final int[] c
since arrays are passed as reference d[0]++ seems like it changes the value of final int[] d = {3}; in the main method.
Is it only the memory address pointing to the array object that cannot be changed or reassigned? For some reason I figured that the values within the array were also unchangeable.
Can somebody please clarify for me?
Thanks,
|
[How To Ask Questions][Read before you PM me]
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16692
|
|
Bill Gorder wrote:
Is it only the memory address pointing to the array object that cannot be changed or reassigned? For some reason I figured that the values within the array were also unchangeable.
No. When declaring a final variable, only the variable is not changeable. And in your example, the variable is a array reference. The reference can't be changed, but the array can be changed.
Henry
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
Bill Gorder
Bartender
Joined: Mar 07, 2010
Posts: 1282
|
|
OK thanks for clearing that up for me Henry.
|
 |
 |
|
|
subject: Parameter Use
|
|
|