Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: code formatting

...

Code Block
bgColor#ffcccc
langjava
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
bgColor#ccccff
langjava
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.

...