jvm十三:ClassLoader的源码文档解读
作者:互联网
* <p> <tt>Class</tt> objects for array classes are not created by class * loaders, but are created automatically as required by the Java runtime. * The class loader for an array class, as returned by {@link * Class#getClassLoader()} is the same as the class loader for its element * type; if the element type is a primitive type, then the array class has no * class loader. (ClassLoader类的部分java文档)
上面一段话的意思就是: 原生类型的数组没有类加载器, 引用类型的数组的类加载器和数组中的元素的类加载器是一样的。
package com.atChina.jvm;
public class Test15 {
public static void main(String[] args) {
// 根据java文档,数组类型的ClassLoader和数组中的元素的ClassLoader是一样的(基本类型除外)
String[] strings = new String[2];
System.out.println(strings.getClass().getClassLoader());
Test15[] test15s = new Test15[2];
System.out.println(test15s.getClass().getClassLoader());
// 基本类型的数组类型没有类加载器
int[] ints = new int[2];
System.out.println(ints.getClass().getClassLoader());
}
}
标签:jvm,ClassLoader,getClassLoader,源码,数组,out,class,加载 来源: https://blog.csdn.net/m0_37564426/article/details/89260237