Class.forName方法
底层
public static Class<?> forName(String className) throws ClassNotFoundException { Class<?> caller = Reflection.getCallerClass(); return forName0(className, true, ClassLoader.getClassLoader(caller), caller); }
public static Class<?> forName(String name, boolean initialize, ClassLoader loader) throws ClassNotFoundException { Class<?> caller = null; SecurityManager sm = System.getSecurityManager(); if (sm != null) { // Reflective call to get caller class is only needed if a security manager // is present. Avoid the overhead of making this call otherwise. caller = Reflection.getCallerClass(); if (sun.misc.VM.isSystemDomainLoader(loader)) { ClassLoader ccl = ClassLoader.getClassLoader(caller); if (!sun.misc.VM.isSystemDomainLoader(ccl)) { sm.checkPermission( SecurityConstants.GET_CLASSLOADER_PERMISSION); } } } return forName0(name, initialize, loader, caller); }
private static native Class<?> forName0(String name, boolean initialize, ClassLoader loader, Class<?> caller)
第一个参数,类的二进制 名称 如 com.xsz.sss.Test
第二个参数,是否初始化
第三个参数,由什么 类加载器 进行 加载
第四个参数,调用者
posted on 2021-04-02 16:47 xingshouzhan 阅读(114) 评论(0) 编辑 收藏 举报