Content deleted Content added
m typo |
→Final variables: Explained how even declaring a variable private final doesn't prevent it from being changed if a public getter is available. |
||
Line 162:
<code>}</code>
The reason for this is that declaring a variable final only affects the reference, not the value of the variable, and Java always passes by reference, which creates a different reference to the same value in the second class. That the value of the private field can be changed without a public setter implies that encapsulation is weak at best, and shouldn't be counted on to protect key values, even in combination with the final keyword.
===Final and inner classes===
|