loadClass()方法
,双亲委派模型的保证,破坏双亲委派模型重写loadClass方法
protected Class<?> loadClass(String name, boolean resolve)
throws ClassNotFoundException
{
synchronized (getClassLoadingLock(name)) {
// First, check if the class has already been loaded
//检查是否被加载过
Class<?> c = findLoadedClass(name);
if (c == null) {
long t0 = System.nanoTime();
try {
//如果父加载器不是空,调用父加载器的loadclass
if (parent != null) {
c = parent.loadClass(name, false);
} else {
//父加载器为空,查询是否被根加载器加载过,没有返回空,抛出异常
c = findBootstrapClassOrNull(name);
}
} catch (ClassNotFoundException e) {
// ClassNotFoundException thrown if class not found
// from the non-null parent class loader
//如果父加载器没找到,抛出ClassNotFound异常
}
//如果父加载器找不到,调用本身的findClass方法加载
if (c == null) {
// If still not found, then invoke findCla