Java – a description of how the classloader loads static variables

Well, this is a novice question about Java, but I don't seem to be sure

I have the following code in my course

private static final String [] LIST_CODE = gerarListCode();
private static final int [][] LIST_INTEGER = new int [][] {
        {947,947},{110,103},{947,958},120},954},{103,107},967},99,104}};

 private static String [] gerarListCode()
    {
        String [] listCode = new String [LIST_INTEGER.length];

        for (int i=0 ; i<LIST_INTEGER.length ; i++)
        {
           //do some stuff      
        }

        return listaUnicode;
    }

This code gives me an initialization exception due to NullPointerException in the following line

String [] listCode = new String [LIST_INTEGER.length];

The variable list is displayed_ Integer is null

Can anyone explain what is the linearity of the class loader process? In other words, does it call this method before loading all the other variables exactly?

Solution

Yes, in short, it's linear

Simply put, start with Java

http://www.developer.com/java/other/article.php/2238491

You should define variables and initialize them in the static initializer block in the correct order, or you can exchange the order of statements as follows:

private static final int [][] LIST_INTEGER = new int [][] { {947,104}};

private static final String [] LIST_CODE = gerarListCode();
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>