本帖最后由 code_geass 于 2013-8-28 18:29 编辑
APPClassLoader和ExtClassLoader都继承了URLClassLoader。Launcher初始化时当前线程默认是AppCLassLoader。委托加载器是ExtClassLoader。然后再委托给BootStrap。如果BootStrap找不到。交给ExtClassLoader的findClass。但是再找不到就是抛异常了吧?在哪里交给AppClassLoader了?- protected Class<?> findClass(final String name)
- throws ClassNotFoundException
- {
- try {
- return AccessController.doPrivileged(
- new PrivilegedExceptionAction<Class>() {
- public Class run() throws ClassNotFoundException {
- String path = name.replace('.', '/').concat(".class");
- Resource res = ucp.getResource(path, false);
- if (res != null) {
- try {
- return defineClass(name, res);
- } catch (IOException e) {
- throw new ClassNotFoundException(name, e);
- }
- } else {
- throw new ClassNotFoundException(name);
- }
- }
- }, acc);
- } catch (java.security.PrivilegedActionException pae) {
- throw (ClassNotFoundException) pae.getException();
- }
- }
复制代码 还有这个findClass方法里最后没有返回值。为什么自己覆盖的那个findClass里已经return了defineClass了最后还要写一个return?
|