Re: Puzzling class field initialization order
Attila Szegedi <[email protected]>
| Newsgroups | gmane.comp.windows.devel.java.advanced |
|---|---|
| Message-ID | <[email protected]> |
On Thu, 06 Sep 2007 15:49:13 +0200, Mark Gorokhov <[email protected]> wrote: > Interesting, commenting out "C c = new C();" prints both not null. To elaborate why it makes a difference: with "new C()", the loading and initialization of C and S goes like this: 1. start loading C 2. it triggers loading S 3. S.IMPL = C.INSTANCE would trigger C loading, but C is already being loaded, and INSTANCE is still null, so it is assigned null ... However, without "new C()", the loading and initialization of C and S goes like this when S.IMPL is accessed: 1. start loading S 2. S.IMPL = C.INSTANCE triggers loading C 3. C would trigger loading S, but it's already being loaded/inited 4. C finishes load/init, INSTANCE is set to non-null 5. control returns to S.IMPL = C.INSTANCE, it is set to non-null Attila. =================================== This list is hosted by DevelopMentor® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com