Why static fields are not initialized in time?
- by Tom Brito
Somebody tell me:
class MyClass {
private static MyClass myClass = new MyClass();
private static final Object obj = new Object();
public MyClass() {
System.out.println(obj); // will print null once
}
}
I wonder, isn't this a bug? Why static objects are not initialized before the constructor runs?