ClassLoader原理扩展

// -- Resource --

    /**
     * Finds the resource with the given name.  A resource is some data
     * (images, audio, text, etc) that can be accessed by class code in a way
     * that is independent of the location of the code.
     *
     * <p> The name of a resource is a '<tt>/</tt>'-separated path name that
     * identifies the resource.
     *
     * <p> This method will first search the parent class loader for the
     * resource; if the parent is <tt>null</tt> the path of the class loader
     * built-in to the virtual machine is searched.  That failing, this method
     * will invoke { @link #findResource(String)} to find the resource.  </p>
     *
     * @param  name
     *         The resource name
     *
     * @return  A <tt>URL</tt> object for reading the resource, or
     *          <tt>null</tt> if the resource could not be found or the invoker
     *          doesn't have adequate  privileges to get the resource.
     *
     * @since  1.1
     */
    public URL getResource(String name) {
    URL url;

    if (parent != null) { ide

     /×当一个装载器被请求装载某个类时,它首先委托本身的parent去装载,若parent能装载,则返回这个 类所对应的Class对象×/ ui

        url = parent.getResource(name);

    } else { this

parent不能装载,则由parent的请求者去装载。×/ url

        url = getBootstrapResource(name);     }     if (url == null) {         url = findResource(name);     }     return url;     }
相关文章
相关标签/搜索