Java Reference
In-Depth Information
class, then the references might be resolved one at a time, as they are used, or perhaps not
at all, if these references were never used during execution of the program.
The only requirement on when resolution is performed is that any errors detected during
resolution must be thrown at a point in the program where some action is taken by the pro-
gram that might, directly or indirectly, require linkage to the class or interface involved
in the error. Using the “static” example implementation choice described above, loading
and linkage errors could occur before the program is executed if they involved a class or
interface mentioned in the class
Test
or any of the further, recursively referenced, classes
and interfaces. In a system that implemented the “laziest” resolution, these errors would be
thrown only when an incorrect symbolic reference is actively used.
The resolution process is described further in §
12.3.3
.
12.1.3. Initialize Test: Execute Initializers
In our continuing example, the Java Virtual Machine is still trying to execute the method
Initialization consists of execution of any class variable initializers and static initializers of
the class
Test
, in textual order. But before
Test
can be initialized, its direct superclass must
be initialized, as well as the direct superclass of its direct superclass, and so on, recursively.
In the simplest case,
Test
has
Object
as its implicit direct superclass; if class
Object
has not
yet been initialized, then it must be initialized before
Test
is initialized. Class
Object
has no
superclass, so the recursion terminates here.
If class
Test
has another class
Super
as its superclass, then
Super
must be initialized before
Test
. This requires loading, verifying, and preparing
Super
if this has not already been done
and, depending on the implementation, may also involve resolving the symbolic references
from
Super
and so on, recursively.
Initialization may thus cause loading, linking, and initialization errors, including such er-
rors involving other types.
12.1.4. Invoke
Test.main
Finally, after completion of the initialization for class
Test
(during which other consequen-
tial loading, linking, and initializing may have occurred), the method
main
of
Test
is invoked.