JVM 数组创建的本质

1、创建数组

创建一个MyParent4[] 数组

public class MyTest4 {

    public static void main(String[] args) {
        MyParent4[] myParent4s = new MyParent4[1];
        System.out.println(myParent4s.getClass());
    }
}

class MyParent4{

    static {
        System.out.println("MyParent4 static block");
    }

}

  打印结构

  说明此处并不符合主动使用的场景,所有不会初始化MyParent4。 打印myParent4s.getClass()的结果为数组类型。[Lcom.example.jvm.classloader.MyParent4 这个类型是JVM在运行期创建出来的。

猜你喜欢

转载自www.cnblogs.com/linlf03/p/10990145.html