JVM:类加载器

Java JVM About 956 words

说明

基于Java11

系统类加载器

ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
System.out.println(systemClassLoader);

输出:AppClassLoader

jdk.internal.loader.ClassLoaders$AppClassLoader@2437c6dc

平台类加载器

ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
ClassLoader platformClassLoader = systemClassLoader.getParent();
System.out.println(platformClassLoader);

输出:PlatformClassLoader

jdk.internal.loader.ClassLoaders$PlatformClassLoader@3f3afe78

启动类加载器

ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
ClassLoader platformClassLoader = systemClassLoader.getParent();
ClassLoader bootstrapClassLoader = platformClassLoader.getParent();
System.out.println(bootstrapClassLoader);

输出:null

null

自定义类使用的加载器

System.out.println(ClassLoaderDemo.class.getClassLoader());

输出:AppClassLoader

jdk.internal.loader.ClassLoaders$AppClassLoader@2437c6dc

String 类使用的加载器

System.out.println(String.class.getClassLoader());

输出:null

null
Views: 1,269 · Posted: 2022-05-21

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓


Today On History
Browsing Refresh