Static field initialization sequence in a class

I am having trouble understanding the initialization order when the class has a static instance of itself. Also, why this behavior is different from String.

See the following example:

public class StaticCheck {
    private static StaticCheck INSTANCE = new StaticCheck();    

    private static final List<String> list =
        new ArrayList<String>(Arrays.asList("hello"));
    private static final Map<String, String> map =
        new HashMap<String, String>();  
    private static final  String name = "hello";

    public static StaticCheck getInstance() {
        return INSTANCE;
    }

    private StaticCheck() {
        load();     
    }

    private void load() {
        if(list != null) {
            System.out.println("list is nonnull");
        } else {
            System.out.println("List is null");
        }
        if(name != null) {
            System.out.println("name is nonnull");
        } else {
            System.out.println("name is null");
        }
        if(map != null) {
            System.out.println("Map is nonnull");
        } else {
            System.out.println("Map is null");
        }
    }

    public static void main(String[] args) {
        StaticCheck check = StaticCheck.getInstance();
    }
}

Output:

List is null
name is nonnull
Map is null

I absolutely do not understand why the field is namenot null. Static fields are initialized in the following cases, as indicated in the class initialization: http://javarevisited.blogspot.in/2012/07/when-class-loading-initialization-java-example.html

Looking at the above example, my thoughts are:

  • , Java. , getInstance(), , . map list .

  • , INSTANCE , , load(), . - list map . , name? .

+4
2

static static. JLS, 12.4.2, :

  1. , C LC. C, (§4.12.4, §8.3.2, §9.3.1).

( )

  1. , , , , .

, INSTANCE , list, map name. 3 null? , name ; . , INSTANCE, .

, INSTANCE list map, list map INSTANCE.

+4

String name - , . , :

if (name != null)

:

if ("hello" != null)

, , .

map list null, , , , INSTANCE, , load(). , static . , map list null. , load() null.

+5

All Articles