public class MyTest4 { public static void main(String[] args) { // MyParent4 myParent4 = new MyParent4(); 毫无疑问这个会触发初始化,属于主动调用 MyParent4 [] myParent4s = new MyParent4[1]; System.out.println(myParent4s.getClass()); System.out.println(myParent4s.getClass().getSuperclass()); MyParent4 [][] myParent4s1 = new MyParent4[1][1]; System.out.println(myParent4s1.getClass()); System.out.println(myParent4s1.getClass().getSuperclass());
System.out.println("=============="); int [] ints = new int[1]; System.out.println(ints.getClass()); System.out.println(ints.getClass().getSuperclass());
byte [] bytes = new byte[1]; System.out.println(bytes.getClass()); System.out.println(bytes.getClass().getSuperclass());
short [] shorts = new short[1]; System.out.println(shorts.getClass()); System.out.println(shorts.getClass().getSuperclass());
class MyParent4{ static { System.out.println("MyParent4 static bloack"); } }
运行结果:
1 2 3 4 5 6 7 8 9 10 11 12 13
class [Lcom.twodragonlake.jvm.classloader.MyParent4; class java.lang.Object class [[Lcom.twodragonlake.jvm.classloader.MyParent4; class java.lang.Object ============== class [I class java.lang.Object class [B class java.lang.Object class [S class java.lang.Object class [Z class java.lang.Object