Final (Java): Difference between revisions

Content deleted Content added
Java strictly passes by value, not by reference as stated here. It is exactly this reason that a reference passed to a method cannot be changed by the method.
Line 136:
</source>
 
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 referencevalue, 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===