Final (Java): Difference between revisions

Content deleted Content added
m Noted common instance where final keyword does not accomplish what is expected.
m typo
Line 95:
Since the obj variable goes out of scope with each iteration of the loop, it is actually redeclared each iteration, allowing the same token (i.e. <code>obj</code>) to be used to represent multiple variables.<ref>{{cite web|url=http://www.cs.cmu.edu/~pattis/15-1XX/15-200/lectures/morejava/lecture.html|title=More Java|last=Pattis|first=Richard E.|work=Advanced Programming/Practicum 15–200|publisher=School of Computer Science [[Carnegie Mellon University]]|accessdate=23 July 2010}}</ref>
 
Although it also appears to break the intent of final variables, modifying the value from another class (by getting the reference via a pubicpublic getter method and changing its value) ''does'' change the value of the referenced object. For instance, according to the semantics of the final keyword, the following unit test should output "68", while in fact it outputs "82" and throws an assertion exception:
 
<code>package test;</code>