Final (Java): Difference between revisions

Content deleted Content added
Line 27:
= Final variables =
 
A '''final [[variable]]''' is [[immutable]]. It can only be assigned to once. 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]], the value of a final variable is not necessarily known at compile time.