Why static fields are not initialized in time?

Posted by Tom Brito on Stack Overflow See other posts from Stack Overflow or by Tom Brito
Published on 2010-03-30T18:39:07Z Indexed on 2010/03/30 18:43 UTC
Read the original article Hit count: 405

Filed under:
|
|
|

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?

© Stack Overflow or respective owner

Related posts about java

Related posts about static