Java Reference
In-Depth Information
< Day Day Up >
6. Class Initialization
This section concerns class loading and initialization.
6.1. Order of class initialization is top to bottom
Prescription:
Ensure that static fields are initialized in an appropriate order. Use lazy initialization
to resolve initialization cycles, which can involve one or more classes.
References:
Puzzles 49
and
52
; [JLS 12.4.2] and [EJ Item 48].
6.2. Timing of
NoClassDefFoundError
is unreliable
Prescription:
Do not catch
NoClassDefFoundError
. Instead, use reflection and catch
ClassNotFoundException
.
More generally, don't catch
Error
or its subclasses.
References:
Puzzle 44
; [JLS 12.2.1].
< Day Day Up >
Search WWH ::
Custom Search