上一篇:类加载二:常量的值并非编译期间可以确定的,则不会放入常量池,引用常量会导致类的初始化
三、数组实例,其类型是由jvm在运行期动态生成,动态生成的类型,其父类型就是Object。代码如下
public class MyTest04 {
public static void main(String[] args) {
//MyParent04 myParent04 = new MyParent04();
MyParent04[] myParent04s = new MyParent04[1];
MyParent04[][] myParent04s1 = new MyParent04[1][1];
System.out.println(myParent04s.getClass());
System.out.println(myParent04s1.getClass());
System.out.println(myParent04s.getClass().getSuperclass());
System.out.println(myParent04s1.getClass().getSuperclass());
int[] is = new int[1];
System.out.println(is.getClass());
System.out.println(is.getClass().getSuperclass());
}
}
class MyParent04 {
static {
System.out.println("MyParent04 loading");
}
}
结果:
class [Lcom.lxl.jvm.MyParent04;
class [[Lcom.lxl.jvm.MyParent04;
class java.lang.Object
class java.lang.Object
class [I
class java.lang.Object
说明:
* 对于数组实例来说,其类型是由jvm在运行期动态生成的,表示为class [Lcom.lxl.jvm.MyParent04这种形式
* 动态生成的类型,其父类型就是Object。
*
* 对于数组来说,JavaDoc经常将构成数组的元素称之为Component,实际上就是将数组降低一个维度后的类型
* 当创建一个数组类型的实例时,并不表示对数组中元素的主动使用,仅仅表示创建了数组实例。
* 而这个数组实例是由虚拟机在运行期动态创建出来的,如果是引用类型就是[L开头。如果是原生类型就是[加一个字母。
* 通常为首字母大写。如[C,[I。boolean型为[Z