Java final Keyword: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
(Created page with "=Internal= * java =Overview= A <tt>final</tt> variable may only be assigned to once. The final variable may be defined unassigned and immediately assigned...")
 
Line 5: Line 5:
=Overview=
=Overview=


A <tt>final</tt> variable may only be assigned to once. The final variable may be defined unassigned and immediately assigned to ("definite assignment").
A <tt>final</tt> variable may only be assigned to once. The final variable may be defined unassigned and immediately assigned to ("definite assignment"). Once a final variable has been assigned, it always contains the same value. If the variable contain a reference of an object, the state of the referred object may change, but the variable will always refer to the same object.
 
An attempt to assign a final variable the second time is detected as compilation error.

Revision as of 20:13, 27 September 2017

Internal

Overview

A final variable may only be assigned to once. The final variable may be defined unassigned and immediately assigned to ("definite assignment"). Once a final variable has been assigned, it always contains the same value. If the variable contain a reference of an object, the state of the referred object may change, but the variable will always refer to the same object.

An attempt to assign a final variable the second time is detected as compilation error.