Parent class loader delegation mechanism Detailed
- In the parent delegation mechanism, each class loader in accordance with parent-child relationships forming a tree structure (actually a logical relationship comprising a), except the root class loader, the rest of the class loader has one and only one parent loader .
-
If a class loader loads successfully Test classes, then the class loader is referred defined class loader , all return Class successfully applied to the object class loader (including custom class loader) are called the initial class loader . [Pictured above, the system class loader can be referred to: define a class loader, class loading system and can be called loader1: initial class loader]
-
Example:
public class MyTest7 { public static void main(String[] args) throws ClassNotFoundException { Class<?> clazz1 = Class.forName("java.lang.String"); System.out.println(clazz1.getClassLoader()); Class<?> clazz2 = Class.forName("Jvm.D"); System.out.println(clazz2.getClassLoader()); } } class D{ } 运行结果: null --》 就根类加载器 sun.misc.Launcher$AppClassLoader@18b4aac2 --》AppClassLoader,就是系统类加载器
-