Java Reference
In-Depth Information
ization code block executes. Similarly, anyone accessing a static field is
guaranteed that the field has been initialized.
What if a static initializer in class X invokes a method in Y , but Y 's static
initializers invoke a method in X to set up its static values? This cyc-
lic static initialization cannot be reliably detected during compilation be-
cause the code for Y may not be written when X is compiled. If cycles
happen, X 's static initializers will have been executed only to the point
where Y 's method was invoked. When Y , in turn, invokes the X meth-
od, that method runs with the rest of the static initializers yet to be ex-
ecuted. Any static fields in X that haven't had their initializers executed
will still have their default values ( false , '/u0000' , zero, or null depend-
ing on their type).
 
Search WWH ::




Custom Search