Java: how to initialize String[]?

后端 未结 11 2226
渐次进展
渐次进展 2020-12-22 18:57

Error

% javac  StringTest.java 
StringTest.java:4: variable errorSoon might not have been initialized
        errorSoon[0] = \"Error, why?\"         


        
11条回答
  •  长情又很酷
    2020-12-22 19:11

    String[] errorSoon = new String[n];
    

    With n being how many strings it needs to hold.

    You can do that in the declaration, or do it without the String[] later on, so long as it's before you try use them.

提交回复
热议问题