Java ClassLoader授权模型?
|
当在
Java API说:
但是在Java反思行动书中有一个关于类加载器的具体章节:
哪个是对的? 解决方法正确的类加载器实现将:>检查课程是否已经加载. 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,根据包代表委派给类加载器的图),一些类加载器实现将在委派之前在本地类路径中查找类. (编辑:鄂州站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
