Final (Java): Difference between revisions

Content deleted Content added
Removed "can someone explain why this is" from the text of the article. Such comments are for discussion pages.
Line 28:
 
A '''final [[variable]]''' is [[immutable]]. It can only be assigned to one value. If the variable is a field of a class, it must be assigned to in the constructor of its class. (Note: If the variable is a reference, this means that the variable cannot be re-bound to reference another object. But the object that it references is still mutable if it was originally mutable.)
 
A <tt>final</tt> variable in Java is equivalent to a <tt>const</tt> variable in C++.
 
Unlike the value of a [[constant (computer science)|constant]], the value of a final variable is not necessarily known at compile time.
 
Instances of inner classes can access fields of the enclosing instance only if they are final.
 
Example: