您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

Java ClassLoader委托模型?

Java ClassLoader委托模型?

正确的类加载器实现将:@H_502_1@

ClassLoader.loadClass的认实现是这样的:@H_502_1@

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,取决于包,委派给类加载器的图),而某些类加载器实现会在委派之前在本地类路径中查找类。@H_502_1@

java 2022/1/1 18:44:35 有453人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶