类 ClassUtils


  • public final class ClassUtils
    extends java.lang.Object
    Utils for Class.
    作者:
    liaochuntao
    • 构造器概要

      构造器 
      构造器 说明
      ClassUtils()  
    • 方法概要

      所有方法 静态方法 具体方法 
      修饰符和类型 方法 说明
      static java.lang.String classPackageAsResourcePath​(java.lang.Class<?> clazz)
      Given an input class object, return a string which consists of the class's package name as a pathname, i.e., all dots ('.') are replaced by slashes ('/').
      static java.lang.String convertClassNameToResourcePath​(java.lang.String className)
      Convert a "."
      static java.lang.Class findClassByName​(java.lang.String className)
      Finds and returns class by className.
      static java.lang.Class<?> forName​(java.lang.String name, java.lang.ClassLoader classLoader)
      Replacement for Class.forName() that also returns Class instances for primitives (e.g.
      static java.lang.String getCanonicalName​(java.lang.Class cls)
      Gets and returns the canonical name of the underlying class.
      static java.lang.String getCanonicalName​(java.lang.Object obj)
      Gets and returns the canonical name of the underlying class.
      static java.lang.ClassLoader getDefaultClassLoader()
      Return the default ClassLoader to use: typically the thread context ClassLoader, if available; the ClassLoader that loaded the ClassUtils class will be used as fallback.
      static java.lang.String getName​(java.lang.Class cls)
      Gets and returns the class name.
      static java.lang.String getName​(java.lang.Object obj)
      Gets and returns className.
      static java.lang.String getSimpleName​(java.lang.Class cls)
      Gets and returns the simple name of the underlying class.
      static java.lang.String getSimpleName​(java.lang.Object obj)
      Gets and returns the simple name of the underlying class as given in the source code.
      static boolean isAssignableFrom​(java.lang.Class clazz, java.lang.Class cls)
      Determines if the class or interface represented by this object is either the same as, or is a superclass or superinterface of, the class or interface represented by the specified parameter.
      private static void registerCommonClasses​(java.lang.Class<?>... commonClasses)
      Register the given common classes with the ClassUtils cache.
      static java.lang.Class<?> resolvePrimitiveClassName​(java.lang.String name)
      Resolve the given class name as primitive class, if appropriate, according to the JVM's naming rules for primitive classes.
      static java.lang.String resourcePathToConvertClassName​(java.lang.String className)
      Convert a "."
      • 从类继承的方法 java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 字段详细资料

      • ARRAY_SUFFIX

        public static final java.lang.String ARRAY_SUFFIX
        另请参阅:
        常量字段值
      • INTERNAL_ARRAY_PREFIX

        private static final java.lang.String INTERNAL_ARRAY_PREFIX
        另请参阅:
        常量字段值
      • NON_PRIMITIVE_ARRAY_PREFIX

        private static final java.lang.String NON_PRIMITIVE_ARRAY_PREFIX
        另请参阅:
        常量字段值
      • PACKAGE_SEPARATOR

        private static final char PACKAGE_SEPARATOR
        另请参阅:
        常量字段值
      • PATH_SEPARATOR

        private static final char PATH_SEPARATOR
        另请参阅:
        常量字段值
      • NESTED_CLASS_SEPARATOR

        private static final char NESTED_CLASS_SEPARATOR
        另请参阅:
        常量字段值
      • SEMICOLON_SEPARATOR

        private static final java.lang.String SEMICOLON_SEPARATOR
        另请参阅:
        常量字段值
      • PRIMITIVE_WRAPPER_TYPE_MAP

        private static final java.util.Map<java.lang.Class<?>,​java.lang.Class<?>> PRIMITIVE_WRAPPER_TYPE_MAP
        Map with primitive wrapper type as key and corresponding primitive type as value, for example: Integer.class -> int.class.
      • PRIMITIVE_TYPE_TO_WRAPPER_MAP

        private static final java.util.Map<java.lang.Class<?>,​java.lang.Class<?>> PRIMITIVE_TYPE_TO_WRAPPER_MAP
        Map with primitive type as key and corresponding wrapper type as value, for example: int.class -> Integer.class.
      • PRIMITIVE_TYPE_NAME_MAP

        private static final java.util.Map<java.lang.String,​java.lang.Class<?>> PRIMITIVE_TYPE_NAME_MAP
        Map with primitive type name as key and corresponding primitive type as value, for example: "int" -> "int.class".
      • PRIMITIVE_TYPE_NAME_MAP_LENGTH

        private static final int PRIMITIVE_TYPE_NAME_MAP_LENGTH
        另请参阅:
        常量字段值
      • COMMON_CLASS_CACHE

        private static final java.util.Map<java.lang.String,​java.lang.Class<?>> COMMON_CLASS_CACHE
        Map with common Java language class name as key and corresponding Class as value. Primarily for efficient deserialization of remote invocations.
    • 构造器详细资料

      • ClassUtils

        public ClassUtils()
    • 方法详细资料

      • registerCommonClasses

        private static void registerCommonClasses​(java.lang.Class<?>... commonClasses)
        Register the given common classes with the ClassUtils cache.
      • findClassByName

        public static java.lang.Class findClassByName​(java.lang.String className)
        Finds and returns class by className.
        参数:
        className - String value for className.
        返回:
        class Instances of the class represent classes and interfaces.
      • isAssignableFrom

        public static boolean isAssignableFrom​(java.lang.Class clazz,
                                               java.lang.Class cls)
        Determines if the class or interface represented by this object is either the same as, or is a superclass or superinterface of, the class or interface represented by the specified parameter.
        参数:
        clazz - Instances of the class represent classes and interfaces.
        cls - Instances of the class represent classes and interfaces.
        返回:
        the value indicating whether objects of the type can be assigned to objects of this class.
      • getName

        public static java.lang.String getName​(java.lang.Class cls)
        Gets and returns the class name.
        参数:
        cls - Instances of the class represent classes and interfaces.
        返回:
        the name of the class or interface represented by this object.
      • getName

        public static java.lang.String getName​(java.lang.Object obj)
        Gets and returns className.
        参数:
        obj - Object instance.
        返回:
        className.
      • getCanonicalName

        public static java.lang.String getCanonicalName​(java.lang.Class cls)
        Gets and returns the canonical name of the underlying class.
        参数:
        cls - Instances of the class represent classes and interfaces.
        返回:
        The canonical name of the underlying class.
      • getCanonicalName

        public static java.lang.String getCanonicalName​(java.lang.Object obj)
        Gets and returns the canonical name of the underlying class.
        参数:
        obj - Object instance.
        返回:
        The canonical name of the underlying class.
      • getSimpleName

        public static java.lang.String getSimpleName​(java.lang.Class cls)
        Gets and returns the simple name of the underlying class.
        参数:
        cls - Instances of the class represent classes and interfaces.
        返回:
        the simple name of the underlying class.
      • getSimpleName

        public static java.lang.String getSimpleName​(java.lang.Object obj)
        Gets and returns the simple name of the underlying class as given in the source code.
        参数:
        obj - Object instance.
        返回:
        the simple name of the underlying class.
      • forName

        public static java.lang.Class<?> forName​(java.lang.String name,
                                                 java.lang.ClassLoader classLoader)
                                          throws java.lang.ClassNotFoundException,
                                                 java.lang.LinkageError
        Replacement for Class.forName() that also returns Class instances for primitives (e.g. "int") and array class names (e.g. "String[]"). Furthermore, it is also capable of resolving nested class names in Java source style (e.g. "java.lang.Thread.State" instead of "java.lang.Thread$State").
        参数:
        name - the name of the Class
        classLoader - the class loader to use (may be null, which indicates the default class loader)
        返回:
        a class instance for the supplied name
        抛出:
        java.lang.ClassNotFoundException - if the class was not found
        java.lang.LinkageError - if the class file could not be loaded
        另请参阅:
        Class.forName(String, boolean, ClassLoader)
      • resolvePrimitiveClassName

        public static java.lang.Class<?> resolvePrimitiveClassName​(java.lang.String name)
        Resolve the given class name as primitive class, if appropriate, according to the JVM's naming rules for primitive classes.

        Also supports the JVM's internal class names for primitive arrays. Does not support the "[]" suffix notation for primitive arrays; this is only supported by forName(String, ClassLoader).

        参数:
        name - the name of the potentially primitive class
        返回:
        the primitive class, or null if the name does not denote a primitive class or primitive array class
      • getDefaultClassLoader

        public static java.lang.ClassLoader getDefaultClassLoader()
        Return the default ClassLoader to use: typically the thread context ClassLoader, if available; the ClassLoader that loaded the ClassUtils class will be used as fallback.

        Call this method if you intend to use the thread context ClassLoader in a scenario where you clearly prefer a non-null ClassLoader reference: for example, for class path resource loading (but not necessarily for Class.forName, which accepts a null ClassLoader reference as well).

        返回:
        the default ClassLoader (only null if even the system ClassLoader isn't accessible)
        另请参阅:
        Thread.getContextClassLoader(), ClassLoader.getSystemClassLoader()
      • classPackageAsResourcePath

        public static java.lang.String classPackageAsResourcePath​(java.lang.Class<?> clazz)
        Given an input class object, return a string which consists of the class's package name as a pathname, i.e., all dots ('.') are replaced by slashes ('/'). Neither a leading nor trailing slash is added. The result could be concatenated with a slash and the name of a resource and fed directly to ClassLoader.getResource(). For it to be fed to Class.getResource instead, a leading slash would also have to be prepended to the returned value.
        参数:
        clazz - the input class. A null value or the default (empty) package will result in an empty string ("") being returned.
        返回:
        a path which represents the package name
        另请参阅:
        ClassLoader.getResource(java.lang.String), Class.getResource(java.lang.String)
      • convertClassNameToResourcePath

        public static java.lang.String convertClassNameToResourcePath​(java.lang.String className)
        Convert a "."-based fully qualified class name to a "/"-based resource path.
        参数:
        className - the fully qualified class name
        返回:
        the corresponding resource path, pointing to the class
      • resourcePathToConvertClassName

        public static java.lang.String resourcePathToConvertClassName​(java.lang.String className)
        Convert a "."-based fully qualified class name to a "/"-based resource path.
        参数:
        className - the fully qualified class name
        返回:
        the corresponding resource path, pointing to the class