ClassLoader loadeClass源码:
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 {
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
}
if (c == null) {
// If still not found, then invoke findClass in order

本文探讨了Java中类加载器的工作原理,特别是双亲委派模型的实现。通过分析ClassLoader的loadClass源码,指出在不破坏双亲模型的情况下,只需重写findClass方法。同时,介绍了自定义类加载器时可能出现的问题,如在Myeclipse环境中,由于自动编译导致的加载问题,以及如何解决。最后,提到了尝试破坏双亲模型时可能导致的异常,强调了Object类的加载顺序和解析的重要性。
最低0.47元/天 解锁文章
135

被折叠的 条评论
为什么被折叠?



