...
Code Block | ||||
---|---|---|---|---|
| ||||
class A { public static int a = B.b(); public static int c() { return 1; } } class B { public static int b() { return A.c(); } } |
This code correctly initializes A.a
to 1 using the Oracle JVM, regardless of whether A
or B
is loaded first. However, the JLS does not guarantee that A.a
to be properly initialized. Furthermore, the initialization cycle makes this sytem harder to maintain, and more likely to break in surprising ways when modified.
...
Code Block | ||||
---|---|---|---|---|
| ||||
class A { public static int a = B.b(); } class B { public static int b() { return B.c(); } public static int c() { return 1; } } |
Risk Assessment
Initialization cycles may lead to unexpected results.
...