类 ClassUtils

    • 字段概要

      字段 
      修饰符和类型 字段 说明
      static java.lang.String ARRAY_SUFFIX
      Suffix for array class names: "[]"
      static java.util.Set<java.lang.Class<?>> PRIMITIVE_TYPES  
      static java.util.Set<java.lang.Class<?>> SIMPLE_TYPES
      Simple Types including: Void Boolean Character Byte Integer Float Double String BigDecimal BigInteger Date Object
    • 构造器概要

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

      所有方法 静态方法 具体方法 
      修饰符和类型 方法 说明
      static boolean arrayTypeEquals​(java.lang.Class<?> oneArrayType, java.lang.Class<?> anotherArrayType)  
      static <T> T cast​(java.lang.Object object, java.lang.Class<T> castType)
      Cast the given object to the specified type
      static java.lang.Object convertPrimitive​(java.lang.Class<?> type, java.lang.String value)  
      protected static java.util.Set<java.lang.String> findClassNamesInArchiveDirectory​(java.io.File classesDirectory, boolean recursive)  
      protected static java.util.Set<java.lang.String> findClassNamesInArchiveFile​(java.io.File jarFile, boolean recursive)  
      static java.util.Set<java.lang.String> findClassNamesInClassPath​(java.io.File archiveFile, boolean recursive)
      Find all class names in class path
      static java.util.Set<java.lang.String> findClassNamesInClassPath​(java.lang.String classPath, boolean recursive)
      Find all class names in class path
      protected static java.util.Set<java.lang.String> findClassNamesInDirectory​(java.io.File classesDirectory, boolean recursive)  
      protected static java.util.Set<java.lang.String> findClassNamesInJarFile​(java.io.File jarFile, boolean recursive)  
      static java.util.Set<java.lang.Class<?>> getAllClasses​(java.lang.Class<?> type, boolean includedSelf, java.util.function.Predicate<java.lang.Class<?>>... classFilters)
      Get all classes(may include self type) from the specified type with filters
      static java.util.Set<java.lang.Class<?>> getAllClasses​(java.lang.Class<?> type, java.util.function.Predicate<java.lang.Class<?>>... classFilters)
      Get all classes from the specified type with filters
      static java.util.Set<java.lang.Class<?>> getAllInheritedTypes​(java.lang.Class<?> type, java.util.function.Predicate<java.lang.Class<?>>... typeFilters)
      Get all inherited types from the specified type
      static java.util.Set<java.lang.Class<?>> getAllInterfaces​(java.lang.Class<?> type, java.util.function.Predicate<java.lang.Class<?>>... interfaceFilters)
      Get all interfaces from the specified type
      static java.util.Set<java.lang.Class<?>> getAllSuperClasses​(java.lang.Class<?> type, java.util.function.Predicate<java.lang.Class<?>>... classFilters)
      Get all super classes from the specified type
      static java.lang.String getSimpleName​(java.lang.Class<?> type)
      Get the simple name of the specified type
      static java.lang.Class<?> getTopComponentType​(java.lang.Class<?> arrayType)  
      static java.lang.Class<?> getTopComponentType​(java.lang.Object array)  
      static java.lang.String getTypeName​(java.lang.Class<?> type)
      Get the name of the specified type
      static java.lang.Class[] getTypes​(java.lang.Object... values)
      Resolve the types of the specified values
      static boolean isAbstractClass​(java.lang.Class<?> type)
      Is the specified type a abstract class or not?
      static boolean isAnnotation​(int modifiers)  
      static boolean isArray​(java.lang.Class<?> type)
      The specified type is array or not?
      static boolean isAssignableFrom​(java.lang.Class<?> superType, java.lang.Class<?> targetType)
      the semantics is same as Class.isAssignableFrom(Class)
      static boolean isConcreteClass​(java.lang.Class<?> type)
      Is the specified type a concrete class or not?
      static boolean isDerived​(java.lang.Class<?> targetType, java.lang.Class<?>... superTypes)
      the semantics is same as Class.isAssignableFrom(Class)
      static boolean isEnum​(int modifiers)  
      static boolean isFinal​(java.lang.Class<?> type)  
      static boolean isGeneralClass​(java.lang.Class<?> type)
      Is the specified type a general class or not?
      protected static boolean isGeneralClass​(java.lang.Class<?> type, java.lang.Boolean isAbstract)
      Is the specified type a general class or not?
      static boolean isGenericClass​(java.lang.Class<?> type)
      Is generic class or not?
      static boolean isPrimitive​(java.lang.Class<?> type)
      The specified type is primitive type or simple type
      static boolean isSimpleType​(java.lang.Class<?> type)
      The specified type is simple type or not
      static boolean isSynthetic​(int modifiers)  
      static boolean isTopLevelClass​(java.lang.Class<?> type)  
      static boolean isWrapperType​(java.lang.Class<?> type)  
      static <T> T newInstance​(java.lang.Class<T> type, java.lang.Object... args)  
      protected static java.lang.String resolveClassName​(java.io.File classesDirectory, java.io.File classFile)  
      static java.lang.String resolveClassName​(java.lang.String resourceName)
      Resolve resource name to class name
      static java.lang.String resolvePackageName​(java.lang.String className)
      Resolve package name under specified class name
      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.Class<?> resolvePrimitiveType​(java.lang.Class<?> type)
      Resolve the primitive class from the specified type
      static java.lang.Class<?> resolveWrapperType​(java.lang.Class<?> primitiveType)
      Resolve the wrapper class from the primitive type
      • 从类继承的方法 java.lang.Object

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

      • ARRAY_SUFFIX

        public static final java.lang.String ARRAY_SUFFIX
        Suffix for array class names: "[]"
        另请参阅:
        常量字段值
      • SIMPLE_TYPES

        public static final java.util.Set<java.lang.Class<?>> SIMPLE_TYPES
        Simple Types including:
        • Void
        • Boolean
        • Character
        • Byte
        • Integer
        • Float
        • Double
        • String
        • BigDecimal
        • BigInteger
        • Date
        • Object
        另请参阅:
        SimpleType
      • PRIMITIVE_TYPES

        public static final java.util.Set<java.lang.Class<?>> PRIMITIVE_TYPES
    • 构造器详细资料

      • ClassUtils

        public ClassUtils()
    • 方法详细资料

      • isArray

        public static boolean isArray​(java.lang.Class<?> type)
        The specified type is array or not?

        It's an optimized alternative for Class.isArray()).

        参数:
        type - the type to test
        返回:
        true if the specified type is an array class, false otherwise
        另请参阅:
        Class.isArray()
      • isConcreteClass

        public static boolean isConcreteClass​(java.lang.Class<?> type)
        Is the specified type a concrete class or not?
        参数:
        type - type to check
        返回:
        true if concrete class, false otherwise.
      • isAbstractClass

        public static boolean isAbstractClass​(java.lang.Class<?> type)
        Is the specified type a abstract class or not?

        参数:
        type - the type
        返回:
        true if type is a abstract class, false otherwise.
      • isGeneralClass

        public static boolean isGeneralClass​(java.lang.Class<?> type)
        Is the specified type a general class or not?

        参数:
        type - the type
        返回:
        true if type is a general class, false otherwise.
      • isGeneralClass

        protected static boolean isGeneralClass​(java.lang.Class<?> type,
                                                java.lang.Boolean isAbstract)
        Is the specified type a general class or not?

        If isAbstract == null, it will not check type is abstract or not.

        参数:
        type - the type
        isAbstract - optional abstract flag
        返回:
        true if type is a general (abstract) class, false otherwise.
      • isTopLevelClass

        public static boolean isTopLevelClass​(java.lang.Class<?> type)
      • isPrimitive

        public static boolean isPrimitive​(java.lang.Class<?> type)
        The specified type is primitive type or simple type

        It's an optimized implementation for Class.isPrimitive().

        参数:
        type - the type to test
        返回:
        另请参阅:
        Class.isPrimitive()
      • isFinal

        public static boolean isFinal​(java.lang.Class<?> type)
      • isSimpleType

        public static boolean isSimpleType​(java.lang.Class<?> type)
        The specified type is simple type or not
        参数:
        type - the type to test
        返回:
        if type is one element of SIMPLE_TYPES, return true, or false
        另请参阅:
        SIMPLE_TYPES
      • convertPrimitive

        public static java.lang.Object convertPrimitive​(java.lang.Class<?> type,
                                                        java.lang.String value)
      • resolvePrimitiveType

        public static java.lang.Class<?> resolvePrimitiveType​(java.lang.Class<?> type)
        Resolve the primitive class from the specified type
        参数:
        type - the specified type
        返回:
        null if not found
      • resolveWrapperType

        public static java.lang.Class<?> resolveWrapperType​(java.lang.Class<?> primitiveType)
        Resolve the wrapper class from the primitive type
        参数:
        primitiveType - the primitive type
        返回:
        null if not found
      • isWrapperType

        public static boolean isWrapperType​(java.lang.Class<?> type)
      • arrayTypeEquals

        public static boolean arrayTypeEquals​(java.lang.Class<?> oneArrayType,
                                              java.lang.Class<?> anotherArrayType)
      • 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.

        参数:
        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
      • isAnnotation

        public static boolean isAnnotation​(int modifiers)
        参数:
        modifiers - Class.getModifiers()
        返回:
        true if this class's modifiers represents an annotation type; false otherwise
        另请参阅:
        Class.isAnnotation()
      • isEnum

        public static boolean isEnum​(int modifiers)
        参数:
        modifiers - Class.getModifiers()
        返回:
        true if this class's modifiers represents an enumeration type; false otherwise
        另请参阅:
        Class.isEnum()
      • isSynthetic

        public static boolean isSynthetic​(int modifiers)
        参数:
        modifiers - Class.getModifiers()
        返回:
        true if this class's modifiers represents a synthetic type; false otherwise
        另请参阅:
        Class.isSynthetic()
      • resolvePackageName

        @Nullable
        public static java.lang.String resolvePackageName​(java.lang.String className)
        Resolve package name under specified class name
        参数:
        className - class name
        返回:
        package name
      • findClassNamesInClassPath

        @Nonnull
        public static java.util.Set<java.lang.String> findClassNamesInClassPath​(java.lang.String classPath,
                                                                                boolean recursive)
        Find all class names in class path
        参数:
        classPath - class path
        recursive - is recursive on sub directories
        返回:
        all class names in class path
      • findClassNamesInClassPath

        public static java.util.Set<java.lang.String> findClassNamesInClassPath​(java.io.File archiveFile,
                                                                                boolean recursive)
        Find all class names in class path
        参数:
        archiveFile - JarFile or class patch directory
        recursive - is recursive on sub directories
        返回:
        all class names in class path
      • findClassNamesInArchiveDirectory

        protected static java.util.Set<java.lang.String> findClassNamesInArchiveDirectory​(java.io.File classesDirectory,
                                                                                          boolean recursive)
      • findClassNamesInArchiveFile

        protected static java.util.Set<java.lang.String> findClassNamesInArchiveFile​(java.io.File jarFile,
                                                                                     boolean recursive)
      • findClassNamesInDirectory

        protected static java.util.Set<java.lang.String> findClassNamesInDirectory​(java.io.File classesDirectory,
                                                                                   boolean recursive)
      • findClassNamesInJarFile

        protected static java.util.Set<java.lang.String> findClassNamesInJarFile​(java.io.File jarFile,
                                                                                 boolean recursive)
      • resolveClassName

        protected static java.lang.String resolveClassName​(java.io.File classesDirectory,
                                                           java.io.File classFile)
      • resolveClassName

        public static java.lang.String resolveClassName​(java.lang.String resourceName)
        Resolve resource name to class name
        参数:
        resourceName - resource name
        返回:
        class name
      • getAllSuperClasses

        public static java.util.Set<java.lang.Class<?>> getAllSuperClasses​(java.lang.Class<?> type,
                                                                           java.util.function.Predicate<java.lang.Class<?>>... classFilters)
        Get all super classes from the specified type
        参数:
        type - the specified type
        classFilters - the filters for classes
        返回:
        non-null read-only Set
      • getAllInterfaces

        public static java.util.Set<java.lang.Class<?>> getAllInterfaces​(java.lang.Class<?> type,
                                                                         java.util.function.Predicate<java.lang.Class<?>>... interfaceFilters)
        Get all interfaces from the specified type
        参数:
        type - the specified type
        interfaceFilters - the filters for interfaces
        返回:
        non-null read-only Set
      • getAllInheritedTypes

        public static java.util.Set<java.lang.Class<?>> getAllInheritedTypes​(java.lang.Class<?> type,
                                                                             java.util.function.Predicate<java.lang.Class<?>>... typeFilters)
        Get all inherited types from the specified type
        参数:
        type - the specified type
        typeFilters - the filters for types
        返回:
        non-null read-only Set
      • isAssignableFrom

        public static boolean isAssignableFrom​(java.lang.Class<?> superType,
                                               java.lang.Class<?> targetType)
        the semantics is same as Class.isAssignableFrom(Class)
        参数:
        superType - the super type
        targetType - the target type
        返回:
        see Class.isAssignableFrom(Class)
      • isGenericClass

        public static boolean isGenericClass​(java.lang.Class<?> type)
        Is generic class or not?
        参数:
        type - the target type
        返回:
        if the target type is not null or void or Void.class, return true, or false
      • getTypes

        public static java.lang.Class[] getTypes​(java.lang.Object... values)
        Resolve the types of the specified values
        参数:
        values - the values
        返回:
        If can't be resolved, return empty class array
      • getTypeName

        public static java.lang.String getTypeName​(java.lang.Class<?> type)
        Get the name of the specified type
        参数:
        type - the specified type
        返回:
        non-null
      • getSimpleName

        public static java.lang.String getSimpleName​(java.lang.Class<?> type)
        Get the simple name of the specified type
        参数:
        type - the specified type
        返回:
        non-null
      • getAllClasses

        public static java.util.Set<java.lang.Class<?>> getAllClasses​(java.lang.Class<?> type,
                                                                      java.util.function.Predicate<java.lang.Class<?>>... classFilters)
        Get all classes from the specified type with filters
        参数:
        type - the specified type
        classFilters - class filters
        返回:
        non-null read-only Set
      • getAllClasses

        public static java.util.Set<java.lang.Class<?>> getAllClasses​(java.lang.Class<?> type,
                                                                      boolean includedSelf,
                                                                      java.util.function.Predicate<java.lang.Class<?>>... classFilters)
        Get all classes(may include self type) from the specified type with filters
        参数:
        type - the specified type
        includedSelf - included self type or not
        classFilters - class filters
        返回:
        non-null read-only Set
      • isDerived

        public static boolean isDerived​(java.lang.Class<?> targetType,
                                        java.lang.Class<?>... superTypes)
        the semantics is same as Class.isAssignableFrom(Class)
        参数:
        targetType - the target type
        superTypes - the super types
        返回:
        see Class.isAssignableFrom(Class)
        从以下版本开始:
        1.0.0
      • newInstance

        public static <T> T newInstance​(java.lang.Class<T> type,
                                        java.lang.Object... args)
      • getTopComponentType

        public static java.lang.Class<?> getTopComponentType​(java.lang.Object array)
      • getTopComponentType

        public static java.lang.Class<?> getTopComponentType​(java.lang.Class<?> arrayType)
      • cast

        public static <T> T cast​(java.lang.Object object,
                                 java.lang.Class<T> castType)
        Cast the given object to the specified type
        类型参数:
        T - the type to cast
        参数:
        object - the object
        castType - the type to cast
        返回:
        the casted instance if and only if object is an instance of castType , null otherwise