Wiki Markup |
---|
According to the _Java Language Specification_ (JLS), [§12.4, "Initialization of Classes and Interfaces" |http://java.sun.com/docs/books/jls/third_edition/html/execution.html#12.4] \[[JLS 2005|AA. Bibliography#JLSReferences#JLS 05]\]: |
Initialization of a class consists of executing its
static
initializers and the initializers forstatic
fields (class variables) declared in the class.
Wiki Markup |
---|
In other words, the presence of a {{static}} field triggers the initialization of a class. However, a static field could depend on the initialization of another class, possibly creating an initialization cycle. The JLS also states in [§8.3.2.1, "Initializers for Class Variables" |http://java.sun.com/docs/books/jls/third_edition/html/classes.html#8.3.2.1] \[[JLS 2005|AA. Bibliography#JLSReferences#JLS 05]\] |
At run time,
static
variables that arefinal
and that are initialized with compile-time constant values are initialized first.
...
Wiki Markup |
---|
The JLS permits implementations to ignore the possibility of such recursive initialization cycles \[[Bloch 2005|AA. Bibliography#BlochReferences#Bloch 05]\]. |
Compliant Solution (Intra-class Cycle)
...
DCL14-CPP. Avoid assumptions about the initialization order between translation units | ||||
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="b217428c84921312-d1f4cc1a-4fbd489a-87ac8447-8b1417b24711d3e09163062a"><ac:plain-text-body><![CDATA[ | [ISO/IEC TR 24772:2010 | http://www.aitcnet.org/isai/] | Initialization of variables [LAV] | ]]></ac:plain-text-body></ac:structured-macro> |
...
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="6f3b345fa44e3d9c-8abac775-4a884032-83919897-2597367f2f87cbc87e36978d"><ac:plain-text-body><![CDATA[ | [[JLS 2005 | AA. Bibliography#JLS References#JLS 05]] | [§8.3.2.1, Initializers for Class Variables | http://java.sun.com/docs/books/jls/third_edition/html/classes.html#8.3.2.1] | ]]></ac:plain-text-body></ac:structured-macro> |
| |||||
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="a9a401ed8e2694fc-d1727cff-46e249e6-a27bb546-407cef423a9c6e306e819936"><ac:plain-text-body><![CDATA[ | [[Bloch 2005 | AA. Bibliography#Bloch References#Bloch 05]] | Puzzle 49. Larger than life | ]]></ac:plain-text-body></ac:structured-macro> | |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="41563c2e2a754984-5662b2a9-41f14a5e-aaedb431-879339ca453fb128ce5c5b88"><ac:plain-text-body><![CDATA[ | [[MITRE 2009 | AA. Bibliography#MITRE References#MITRE 09]] | [CWE-665 | http://cwe.mitre.org/data/definitions/665.html]. Improper initialization | ]]></ac:plain-text-body></ac:structured-macro> |
...