Consider a Java class with static fields only and no constructor:
public class OnlyStatic {
static O1 o1 = new o1();
static O2 o2 = new o2();
public static int compute(int whatever) {
return o1.foo+o2.bar+whatever;
}
}
In a different class, the method compute is used, either by static import:
static import OnlyStatic.compute
int a = OnlyStatic.compute(3);
Or directly, assuming the caller is in the same package:
int a = OnlyStatic.compute(3);
When are o1 and o2 initialized? At the import, or when compute() is called for the first time?
The objects
o1ando2are not available to yourstaticcontext without making themstaticalso.JVMS states that
Further
So in your case, when the static method
compute()is first executed.