Final (Java): Difference between revisions

Content deleted Content added
Bender the Bot (talk | contribs)
m Final variables: HTTP → HTTPS for Carnegie Mellon CS, replaced: http://www.cs.cmu.edu/ → https://www.cs.cmu.edu/
Bluelinking 1 books for verifiability.) #IABot (v2.1alpha3
Line 155:
===Blank final===
 
The '''blank final''', which was introduced in Java 1.1, is a final variable whose declaration lacks an initializer.<ref>{{cite book|last=Flanagan|first=David |title=Java in a Nutshell|url=httphttps://webarchive.deu.edu.trorg/docdetails/oreily/java/javanut/ch05_06.htmjavainnutshelld100flan|edition=2nd|date=May 1997 |publisher=O'Reilly|isbn=1-56592-262-X|chapter=Chapter 5 Inner Classes and Other New Language Features:5.6 Other New Features of Java 1.1|url-access=registration}}</ref><ref>{{cite web|url=http://docs.oracle.com/javase/specs/jls/se8/html/jls-4.html#jls-4.12.4|title=Chapter 4. Types, Values, and Variables|year=2015|work=The Java® Language Specification (Java SE 8 Edition)|publisher=Oracle America, Inc.|access-date=23 Feb 2015}}</ref> Previous to Java 1.1, a final variable was required to have an initializer. A blank final, by definition of "final", can only be assigned once. i.e. it must be unassigned when an assignment occurs. In order to do this, a Java compiler runs a flow analysis to ensure that, for every assignment to a blank final variable, the variable is definitely unassigned before the assignment; otherwise a compile-time error occurs.<ref name="define_assignment">{{cite web|url=http://docs.oracle.com/javase/specs/jls/se8/html/jls-16.html|title=Definite Assignment|year=2015|work=The Java® Language Specification (Java SE 8 Edition)|publisher=Oracle America, Inc.|access-date=29 Oct 2016}}</ref>
 
<source lang="java">