Class ChildFirstClassLoader

  • All Implemented Interfaces:
    Closeable, AutoCloseable

    public final class ChildFirstClassLoader
    extends URLClassLoader
    An almost trivial no-fuss implementation of a class loader following the child-first delegation model. Based on code from Ceki Gulcu
    Author:
    Paul Gregoire (mondain@gmail.com)
    • Constructor Detail

      • ChildFirstClassLoader

        public ChildFirstClassLoader​(URL[] urls)
      • ChildFirstClassLoader

        public ChildFirstClassLoader​(URL[] urls,
                                     ClassLoader parent)
    • Method Detail

      • loadClass

        protected Class<?> loadClass​(String name,
                                     boolean resolve)
                              throws ClassNotFoundException
        We override the parent-first behavior established by java.lang.Classloader.

        The implementation is surprisingly straightforward.

        Overrides:
        loadClass in class ClassLoader
        Parameters:
        name - the name of the class to load, should not be null
        resolve - flag that indicates whether the class should be resolved
        Returns:
        the loaded class, never null
        Throws:
        ClassNotFoundException - if the class could not be loaded
      • getResource

        public URL getResource​(String name)
        Override the parent-first resource loading model established by java.lang.Classloader with child-first behavior.
        Overrides:
        getResource in class ClassLoader
        Parameters:
        name - the name of the resource to load, should not be null
        Returns:
        a URL for the resource, or null if it could not be found