public class ClassHelper extends Object
| 限定符和类型 | 字段和说明 |
|---|---|
static String |
ARRAY_SUFFIX
Suffix for array class names: "[]"
|
static String |
PACKAGE_SEPARATOR
package separator string
|
static char |
PACKAGE_SEPARATOR_CHAR
package separator char
|
| 构造器和说明 |
|---|
ClassHelper() |
| 限定符和类型 | 方法和说明 |
|---|---|
static Class<?> |
forName(String name)
Same as
Class.forName(), except that it works for primitive types. |
static Class<?> |
forName(String name,
ClassLoader classLoader)
Replacement for
Class.forName() that also returns Class instances for primitives (like "int") and
array class names (like "String[]"). |
static Class<?> |
forNameWithCallerClassLoader(String name,
Class<?> caller)
to initialize clss by name from caller.
|
static Class<?> |
forNameWithThreadContextClassLoader(String name)
To fix name with thread context of class loader
|
static ClassLoader |
getCallerClassLoader(Class<?> caller)
get class loader from caller calss
|
static ClassLoader |
getClassLoader()
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 ClassLoader |
getClassLoader(Class<?> cls)
get class loader
|
static String |
getClassName(Class<?> cls)
get class simple name from
Class instance. |
static String |
getFullClassName(Class<?> cls)
get new class name with full package
|
static String |
getInternalName(String clsName)
get class internal name from Class.getName(). sub class like A$B to A.B
|
static long |
getLastModifyTime(Class<?> cls) |
static String |
getPackage(Class<?> cls) |
static boolean |
hasDefaultConstructor(Class<?> cls)
To test class if has default constructor method
|
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 |
toShortString(Object obj)
To get short message of object instance.
|
public static final char PACKAGE_SEPARATOR_CHAR
public static String getInternalName(String clsName)
clsName - class namepublic static long getLastModifyTime(Class<?> cls)
public static Class<?> forNameWithThreadContextClassLoader(String name) throws ClassNotFoundException
name - class nameClassNotFoundException - if class not foundpublic static Class<?> forNameWithCallerClassLoader(String name, Class<?> caller) throws ClassNotFoundException
name - class namecaller - caller of Class typeClassNotFoundException - if class not foundpublic static ClassLoader getCallerClassLoader(Class<?> caller)
caller - caller of Class typepublic static ClassLoader getClassLoader(Class<?> cls)
cls - target class to get ownered class loaderpublic static ClassLoader getClassLoader()
Call this method if you intend to use the thread context ClassLoader in a scenario where you absolutely need 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)Thread.getContextClassLoader()public static Class<?> forName(String name) throws ClassNotFoundException
Class.forName(), except that it works for primitive types.public static Class<?> forName(String name, ClassLoader classLoader) throws ClassNotFoundException, LinkageError
Class.forName() that also returns Class instances for primitives (like "int") and
array class names (like "String[]").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(java.lang.String).
name - the name of the potentially primitive classnull if the name does not denote a primitive class or primitive
array classpublic static String toShortString(Object obj)
obj - target objectpublic static String getClassName(Class<?> cls)
Class instance. cls - target classpublic static boolean hasDefaultConstructor(Class<?> cls)
cls - target classCopyright © 2022 Baidu, Inc.. All rights reserved.