这是来自OCJP的例子.我写了以下代码
public class Test {
static int x[];
static {
x[0] = 1;
}
public static void main(String... args) {
}
}
Run Code Online (Sandbox Code Playgroud)
输出: java.lang.ExceptionInInitializerError
引起:java.lang.NullPointerException at x[0] = 1;
它为什么扔NullPointerException而不是ArrayIndexOutOfBoundException.