java.lang.Class utility methods.
Mainly for internal use within the framework.
TypeUtils, ReflectionUtils
| Modifier and Type | Field and Description |
|---|---|
| public static final String | ARRAY_SUFFIX
Suffix for array class names: |
| public static final String | CGLIB_CLASS_SEPARATOR
The CGLIB class separator: |
| public static final String | CLASS_FILE_SUFFIX
The ".class" file suffix. |
| private static final Map | commonClassCache
Map with common Java language class name as key and corresponding Class as value. |
| private static final Class | EMPTY_CLASS_ARRAY
A reusable empty class array constant. |
| private static final Map | interfaceMethodCache
Cache for equivalent methods on an interface implemented by the declaring class. |
| private static final String | INTERNAL_ARRAY_PREFIX
Prefix for internal array class names: |
| private static final Set | javaLanguageInterfaces
Common Java language interfaces which are supposed to be ignored when searching for 'primary' user-level interfaces. |
| private static final char | NESTED_CLASS_SEPARATOR
The nested class separator character: |
| private static final int | NON_OVERRIDABLE_MODIFIER
Precomputed value for the combination of private, static and final modifiers. |
| private static final String | NON_PRIMITIVE_ARRAY_PREFIX
Prefix for internal non-primitive array class names: |
| private static final int | OVERRIDABLE_MODIFIER
Precomputed value for the combination of public and protected modifiers. |
| private static final char | PACKAGE_SEPARATOR
The package separator character: |
| private static final char | PATH_SEPARATOR
The path separator character: |
| private static final Map | primitiveTypeNameMap
Map with primitive type name as key and corresponding primitive
type as value, for example: |
| private static final Map | primitiveTypeToWrapperMap
Map with primitive type as key and corresponding wrapper
type as value, for example: |
| private static final Map | primitiveWrapperTypeMap
Map with primitive wrapper type as key and corresponding primitive
type as value, for example: |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public static String | Returns: the built-up resource paththe Class whose package will be used as the base clazz, String the resource name to append. A leading slash is optional. resourceName)Return a path suitable for use with |
| public static String | Returns: a String of form "[com.foo.Bar, com.foo.Baz]"an array of Class objects classes)Build a String that consists of the names of the classes/interfaces in the given array. |
| public static String | Returns: a String of form "[com.foo.Bar, com.foo.Baz]"a Collection of Class objects (may be classes)null)Build a String that consists of the names of the classes/interfaces in the given collection. |
| public static String | Returns: a path which represents the package namethe input class. A clazz)null value or the default
(empty) package will result in an empty string ("") being returned.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 ('/'). |
| public static String | Returns: the corresponding resource path, pointing to the classthe fully qualified class name className)Convert a "."-based fully qualified class name to a "/"-based resource path. |
| public static String | Returns: the corresponding fully qualified class namethe resource path pointing to a class resourcePath)Convert a "/"-based resource path to a "."-based fully qualified class name. |
| public static Class | Returns: the merged interface as Classthe interfaces to merge interfaces, ClassLoader the ClassLoader to create the composite Class in classLoader)Create a composite interface Class for the given interfaces, implementing the given interfaces in one single Class. |
| public static Class | Returns: the common ancestor (i.e. common superclass, one interface extending the other), ornull if none found. If any of the
given classes is null, the other class will be returned.the class to introspect clazz1, Class<?> the other class to introspect clazz2)Determine the common ancestor of the given classes, if any. |
| private static Method | |
| private static Set | |
| public static Class | Returns: a class instance for the supplied namethe name of the Class name, ClassLoader the class loader to use
(may be classLoader)null, which indicates the default class loader)Replacement for |
| public static Class | Returns: all interfaces that the given instance implements as an arraythe instance to analyze for interfaces instance)Return all interfaces that the given instance implements as an array, including ones implemented by superclasses. |
| public static Set | Returns: all interfaces that the given instance implements as a Setthe instance to analyze for interfaces instance)Return all interfaces that the given instance implements as a Set, including ones implemented by superclasses. |
| public static Class | Returns: all interfaces that the given object implements as an arraythe class to analyze for interfaces clazz)Return all interfaces that the given class implements as an array, including ones implemented by superclasses. |
| public static Class | Returns: all interfaces that the given object implements as an arraythe class to analyze for interfaces clazz, ClassLoader the ClassLoader that the interfaces need to be visible in
(may be classLoader)null when accepting all declared interfaces)Return all interfaces that the given class implements as an array, including ones implemented by superclasses. |
| public static Set | Returns: all interfaces that the given object implements as a Setthe class to analyze for interfaces clazz)Return all interfaces that the given class implements as a Set, including ones implemented by superclasses. |
| public static Set | Returns: all interfaces that the given object implements as a Setthe class to analyze for interfaces clazz, ClassLoader the ClassLoader that the interfaces need to be visible in
(may be classLoader)null when accepting all declared interfaces)Return all interfaces that the given class implements as a Set, including ones implemented by superclasses. |
| public static String | Returns: the file name of the ".class" filethe class clazz)Determine the name of the class file, relative to the containing package: e.g. "String.class" |
| public static <T> Constructor | Returns: the constructor, ornull if not foundthe clazz to analyze clazz, Class<?>... the parameter types of the method paramTypes)Determine whether the given class has a public constructor with the given signature,
and return it if available (else return |
| public static ClassLoader | Returns: the default ClassLoader (onlynull if even the system
ClassLoader isn't accessible)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. |
| public static String | Returns: the qualified name of the classthe value to introspect value)Return a descriptive name for the given object's type: usually simply the class name, but component type class name + "[]" for arrays, and an appended list of implemented interfaces for JDK proxies. |
| public static Method | Returns: the corresponding interface method, or the original method if none foundthe method to be invoked, potentially from an implementation class method)
Deprecated
in favor of
getInterfaceMethodIfPossible(Method, Class)
Determine a corresponding interface method for the given method handle, if possible. |
| public static Method | Returns: the corresponding interface method, or the original method if none foundthe method to be invoked, potentially from an implementation class method, Class<?> the target class to check for declared interfaces targetClass)Determine a corresponding interface method for the given method handle, if possible. |
| public static Method | Returns: the method (nevernull)the clazz to analyze clazz, String the name of the method methodName, Class<?>... the parameter types of the method
(may be paramTypes)null to indicate any signature)Determine whether the given class has a public method with the given signature,
and return it if available (else throws an |
| public static int | Returns: the number of methods with the given namethe clazz to check clazz, String the name of the method methodName)Return the number of methods with a given name (with any argument types), for the given class and/or its superclasses. |
| public static Method | Returns: the method, ornull if not foundthe clazz to analyze clazz, String the name of the method methodName, Class<?>... the parameter types of the method
(may be paramTypes)null to indicate any signature)Determine whether the given class has a public method with the given signature,
and return it if available (else return |
| private static Method | |
| public static Method | Returns: the specific target method, or the original method if thetargetClass does not implement itthe method to be invoked, which may come from an interface method, Class<?> the target class for the current invocation
(may be targetClass)null or may not even implement the method)Given a method, which may come from an interface, and a target class used
in the current reflective invocation, find the corresponding target method
if there is one — for example, the method may be |
| public static String | Returns: the package name, or the empty String if the class is defined in the default packagethe class clazz)Determine the name of the package of the given class,
e.g. "java.lang" for the |
| public static String | Returns: the package name, or the empty String if the class is defined in the default packagethe fully-qualified class name fqClassName)Determine the name of the package of the given fully-qualified class name,
e.g. "java.lang" for the |
| public static String | Returns: the qualified name of the methodthe method method)Return the qualified name of the given method, consisting of fully qualified interface/class name + "." + method name. |
| public static String | Returns: the qualified name of the methodthe method method, Class<?> the clazz that the method is being invoked on
(may be clazz)null to indicate the method's declaring class)Return the qualified name of the given method, consisting of fully qualified interface/class name + "." + method name. |
| public static String | Returns: the qualified name of the classthe class clazz)Return the qualified name of the given class: usually simply the class name, but component type class name + "[]" for arrays. |
| public static String | Returns: the class name of the class without the package namethe className to get the short name for className)Get the class name without the qualified package name. |
| public static String | Returns: the class name of the class without the package namethe class to get the short name for clazz)Get the class name without the qualified package name. |
| public static String | Returns: the short name rendered in a standard JavaBeans property formatthe class clazz)Return the short string name of a Java class in uncapitalized JavaBeans property format. |
| public static Method | Returns: the static method, ornull if no static method was foundthe class which defines the method clazz, String the static method name methodName, Class<?>... the parameter types to the method args)Return a public static method of a class. |
| public static Class | Returns: the user-defined classthe instance to check instance)Return the user-defined class for the given instance: usually simply the class of the given instance, but the original class in case of a CGLIB-generated subclass. |
| public static Class | Returns: the user-defined classthe class to check clazz)Return the user-defined class for the given class: usually simply the given class, but the original class in case of a CGLIB-generated subclass. |
| public static boolean | Returns: whether there is at least one method with the given namethe clazz to check clazz, String the name of the method methodName)Does the given class or one of its superclasses at least have one or more methods with the supplied name (with any argument types)? |
| public static boolean | Returns: whether the class has a corresponding constructorthe clazz to analyze clazz, Class<?>... the parameter types of the method paramTypes)Determine whether the given class has a public constructor with the given signature. |
| public static boolean | |
| public static boolean | |
| public static boolean | Returns: true if rhsType is assignable to lhsTypethe target type (left-hand side (LHS) type) lhsType, Class<?> the value type (right-hand side (RHS) type) that should
be assigned to the target type rhsType)Check if the right-hand side type may be assigned to the left-hand side type, assuming setting by reflection. |
| public static boolean | Returns: if the type is assignable from the valuethe target type type, Object the value that should be assigned to the type value)Determine if the given type is assignable from the given value, assuming setting by reflection. |
| public static boolean | isCacheSafe(Class<?>
the class to analyze clazz, ClassLoader the ClassLoader to potentially cache metadata in
(may be classLoader)null which indicates the system class loader)Check whether the given class is cache-safe in the given context, i.e. whether it is loaded by the given ClassLoader or a parent of it. |
| public static boolean | isCglibProxy(Object
the object to check object)
Deprecated
as of 5.2, in favor of custom (possibly narrower) checks
such as for a Spring AOP proxy
Check whether the given object is a CGLIB proxy. |
| public static boolean | isCglibProxyClass(Class<?>
the class to check clazz)
Deprecated
as of 5.2, in favor of custom (possibly narrower) checks
or simply a check for containing
CGLIB_CLASS_SEPARATOR
Check whether the specified class is a CGLIB-generated class. |
| public static boolean | isCglibProxyClassName(String
the class name to check className)
Deprecated
as of 5.2, in favor of custom (possibly narrower) checks
or simply a check for containing
CGLIB_CLASS_SEPARATOR
Check whether the specified class name is a CGLIB-generated class. |
| private static boolean | |
| public static boolean | Returns: true if the supplied class is an inner classDetermine if the supplied class is an inner class, i.e. a non-static member of an enclosing class. |
| public static boolean | isJavaLanguageInterface(Class<?>
the interface to check ifc)Determine whether the given interface is a common Java language interface:
|
| public static boolean | Returns: true if the class is a lambda implementation classthe class to check clazz)Determine if the supplied |
| private static boolean | isLoadable(Class<?>
the class to check (typically an interface) clazz, ClassLoader the ClassLoader to check against classLoader)Check whether the given class is loadable in the given ClassLoader. |
| private static boolean | isOverridable(Method
the method to check method, Class<?> the target class to check against targetClass)Determine whether the given method is overridable in the given target class. |
| public static boolean | Returns: whether the specified class is present (including all of its superclasses and interfaces)the name of the class to check className, ClassLoader the class loader to use
(may be classLoader)null which indicates the default class loader)Determine whether the |
| public static boolean | Returns: whether the given class is a primitive array classthe class to check clazz)Check if the given class represents an array of primitives, i.e. boolean, byte, char, short, int, long, float, or double. |
| public static boolean | Returns: true if the given class represents a primitive, void, or
a wrapper classthe class to check clazz)Check if the given class represents a primitive (i.e. boolean, byte,
char, short, int, long, float, or double), |
| public static boolean | Returns: whether the given class is a primitive wrapper classthe class to check clazz)Check if the given class represents a primitive wrapper, i.e. Boolean, Byte, Character, Short, Integer, Long, Float, Double, or Void. |
| public static boolean | Returns: whether the given class is a primitive wrapper array classthe class to check clazz)Check if the given class represents an array of primitive wrappers, i.e. Boolean, Byte, Character, Short, Integer, Long, Float, or Double. |
| public static boolean | Returns: whether the given type represents a "simple" value type, suggesting value-based data binding andtoString outputthe type to check type)Delegate for |
| public static boolean | Returns: true if the supplied class is a static classDetermine if the supplied class is a static class. |
| public static boolean | Returns: true if the method can be considered as user-declared; false otherwisethe method to check method)Determine whether the given method is declared by the user or at least pointing to a user-declared method. |
| public static boolean | isVisible(Class<?>
the class to check (typically an interface) clazz, ClassLoader the ClassLoader to check against
(may be classLoader)null in which case this method will always return true)Check whether the given class is visible in the given ClassLoader. |
| public static boolean | Returns: true if the type represents Void or voidthe type to check type)Determine if the given type represents either |
| public static boolean | matchesTypeName(Class<?>
the class to check clazz, String the type name to match typeName)Check whether the given class matches the user-specified type name. |
| public static ClassLoader | Returns: the original thread context ClassLoader, ornull if not overriddenthe actual ClassLoader to use for the thread context classLoaderToUse)Override the thread context ClassLoader with the environment's bean ClassLoader if necessary, i.e. if the bean ClassLoader is not equivalent to the thread context ClassLoader already. |
| private static void | registerCommonClasses(Class<?>... commonClasses)
Register the given common classes with the ClassUtils cache. |
| public static Class | Returns: a class instance for the supplied namethe name of the Class className, ClassLoader the class loader to use
(may be classLoader)null, which indicates the default class loader)Resolve the given class name into a Class instance. |
| public static Class | Returns: the primitive class, ornull if the name does not denote
a primitive class or primitive array classthe name of the potentially primitive class name)Resolve the given class name as primitive class, if appropriate, according to the JVM's naming rules for primitive classes. |
| public static Class | Returns: the original class, or a primitive wrapper for the original primitive typethe class to check clazz)Resolve the given class if it is a primitive class, returning the corresponding primitive wrapper type instead. |
| public static Class | Returns: theClass arraythe collection)Collection to copyCopy the given |