Class ClassLoaderUtil


  • public class ClassLoaderUtil
    extends java.lang.Object
    This utility class is used for resolving a right ClassLoader from a given class. getClassLoader always returns a non-null ClassLoader even a class is loaded through the bootstrap class loader of JRE.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.lang.ClassLoader BOOTSTRAP_CLASSLOADER  
    • Constructor Summary

      Constructors 
      Constructor Description
      ClassLoaderUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      private static java.lang.ClassLoader getBootstrapClassLoader()
      Lazily create a singleton BootstrapClassLoader.
      static java.lang.ClassLoader getClassLoader()
      Returns a fallback class loader.
      static java.lang.ClassLoader getClassLoader​(java.lang.Class<?> cls)
      Returns the class loader used for loading the specified class.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • BOOTSTRAP_CLASSLOADER

        private static volatile java.lang.ClassLoader BOOTSTRAP_CLASSLOADER
    • Constructor Detail

      • ClassLoaderUtil

        public ClassLoaderUtil()
    • Method Detail

      • getBootstrapClassLoader

        private static java.lang.ClassLoader getBootstrapClassLoader()
        Lazily create a singleton BootstrapClassLoader. This class loader might be necessary when ICU4J classes are initialized by bootstrap class loader.
        Returns:
        The BootStrapClassLoader singleton instance
      • getClassLoader

        public static java.lang.ClassLoader getClassLoader​(java.lang.Class<?> cls)
        Returns the class loader used for loading the specified class.
        Parameters:
        cls - The class
        Returns:
        the class loader
      • getClassLoader

        public static java.lang.ClassLoader getClassLoader()
        Returns a fallback class loader.
        Returns:
        A class loader