Final fields initialization order
问题 Here is some code that calls static method A.f() on class that is not initialized yet. Can someone explain behavior of this code in terms of JLS? class A { final static Object b = new B(); final static int S1 = 1; final static Integer S2 = 2; static void f() { System.out.println(S1); System.out.println(S2); } } class B { static { A.f(); } } public class App { public static void main( String[] args ) { A.f(); } } Output: 1 null 1 2 回答1: A.f() in App.main() triggers initialization of class A .