正确的类加载器实现将:@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@