数组定义与类的初始化
SuperClass类:
public class SuperClass {
public static String staticVariable = "staticVariable";
public static final String STATIC_CONSTANT = "STATIC_CONSTANT";
static {
System.out.println("SuperClass is loading.");
}
}
现有一段代码,创建了SuperClass数组:
public class MainClass {
static {
System.out.println("MainClass is loading.");
}
public static void main(String[] args) {
SuperClass[] superClasses = new SuperClass[3];
}
}
上述代码执行后,控制台输出:
MainClass is loading.
可见,通过数组定义来引用类,并不会触发类的初始化。