public final class ClassUtils extends Object
| 限定符和类型 | 字段和说明 |
|---|---|
static String |
ARRAY_SUFFIX |
| 限定符和类型 | 方法和说明 |
|---|---|
static String |
classPackageAsResourcePath(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 String |
convertClassNameToResourcePath(String className)
Convert a "."
|
static Class |
findClassByName(String className)
Finds and returns class by className.
|
static Class<?> |
forName(String name,
ClassLoader classLoader)
Replacement for
Class.forName() that also returns Class instances for primitives (e.g. |
static String |
getCanonicalName(Class cls)
Gets and returns the canonical name of the underlying class.
|
static String |
getCanonicalName(Object obj)
Gets and returns the canonical name of the underlying class.
|
static 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 String |
getName(Class cls)
Gets and returns the class name.
|
static String |
getName(Object obj)
Gets and returns className.
|
static String |
getSimpleName(Class cls)
Gets and returns the simple name of the underlying class.
|
static String |
getSimpleName(Object obj)
Gets and returns the simple name of the underlying class as given in the source code.
|
static boolean |
isAssignableFrom(Class clazz,
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.
|
static Class<?> |
resolvePrimitiveClassName(String name)
Resolve the given class name as primitive class, if appropriate, according to the JVM's naming rules for
primitive classes.
|
static String |
resourcePathToConvertClassName(String className)
Convert a "."
|
public static Class findClassByName(String className)
className - String value for className.public static boolean isAssignableFrom(Class clazz, Class cls)
clazz - Instances of the class represent classes and interfaces.cls - Instances of the class represent classes and interfaces.public static String getName(Class cls)
cls - Instances of the class represent classes and interfaces.public static String getName(Object obj)
obj - Object instance.public static String getCanonicalName(Class cls)
cls - Instances of the class represent classes and interfaces.public static String getCanonicalName(Object obj)
obj - Object instance.public static String getSimpleName(Class cls)
cls - Instances of the class represent classes and interfaces.public static String getSimpleName(Object obj)
obj - Object instance.public static Class<?> forName(String name, ClassLoader classLoader) throws ClassNotFoundException, LinkageError
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 ClassclassLoader - the class loader to use (may be null, which indicates the default class loader)ClassNotFoundException - if the class was not foundLinkageError - if the class file could not be loadedClass.forName(String, boolean, ClassLoader)public static Class<?> resolvePrimitiveClassName(String name)
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 classnull if the name does not denote a primitive class or primitive array
classpublic static ClassLoader getDefaultClassLoader()
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).
null if even the system ClassLoader isn't accessible)Thread.getContextClassLoader(),
ClassLoader.getSystemClassLoader()public static String classPackageAsResourcePath(Class<?> clazz)
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.ClassLoader.getResource(java.lang.String),
Class.getResource(java.lang.String)public static String convertClassNameToResourcePath(String className)
className - the fully qualified class nameCopyright © 2018–2024 Alibaba Group. All rights reserved.