栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Java ClassLoader委托模型?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Java ClassLoader委托模型?

正确的类加载器实现将:

  1. 检查该类是否已经加载。
  2. 通常要求父类加载器加载该类
  3. 尝试在自己的班级路径中查找班级。

ClassLoader.loadClass的默认实现是这样的:

protected synchronized Class<?> loadClass(String name, boolean resolve) {  // First, check if this class loader has directly defined the class or if the  // JVM has initiated the class load with this class loader.  Class<?> result = findLoadedClass(name);  if (result == null) {    try {      // Next, delegate to the parent.      result = getParent().loadClass(name);    } catch (ClassNotFoundException ex) {      // Finally, search locally if the parent could not find the class.      result = findClass(ex);    }  }  // As a remnant of J2SE 1.0.2, link the class if a subclass of the class  // loader class requested it (the JVM never calls the method,  // loadClass(String) passes false, and the protected access modifier prevents  // callers from passing true).  if (resolve) {    resolveClass(result);  }  return result;}

一些类加载器实现将委派给其他非父类加载器(例如,OSGi,取决于包,委派给类加载器的图),而某些类加载器实现会在委派之前在本地类路径中查找类。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/431392.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号