类 ClassUtils
- java.lang.Object
-
- org.apache.dubbo.common.utils.ClassUtils
-
public class ClassUtils extends Object
-
-
字段概要
字段 修饰符和类型 字段 说明 static StringARRAY_SUFFIXSuffix for array class names: "[]"static Set<Class<?>>SIMPLE_TYPES
-
构造器概要
构造器 构造器 说明 ClassUtils()
-
方法概要
所有方法 静态方法 具体方法 已过时的方法 修饰符和类型 方法 说明 static ObjectconvertPrimitive(Class<?> type, String value)static Class<?>forName(String name)Same asClass.forName(), except that it works for primitive types.static Class<?>forName(String name, ClassLoader classLoader)Replacement forClass.forName()that also returns Class instances for primitives (like "int") and array class names (like "String[]").static Class<?>forNameWithCallerClassLoader(String name, Class<?> caller)static Class<?>forNameWithThreadContextClassLoader(String name)static Set<Class<?>>getAllInheritedTypes(Class<?> type, Predicate<Class<?>>... typeFilters)Get all inherited types from the specified typestatic Set<Class<?>>getAllInterfaces(Class<?> type, Predicate<Class<?>>... interfaceFilters)Get all interfaces from the specified typestatic Set<Class<?>>getAllSuperClasses(Class<?> type, Predicate<Class<?>>... classFilters)Get all super classes from the specified typestatic ClassLoadergetCallerClassLoader(Class<?> caller)static ClassLoadergetClassLoader()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 ClassLoadergetClassLoader(Class<?> clazz)get class loaderstatic booleanisAssignableFrom(Class<?> superType, Class<?> targetType)the semantics is same asClass.isAssignableFrom(Class)static booleanisGenericClass(Class<?> type)Is generic class or not?static booleanisPresent(String className, ClassLoader classLoader)Test the specified class name is present in theClassLoaderstatic booleanisPrimitive(Class<?> type)已过时。as 2.7.6, useClass.isPrimitive()plusisSimpleType(Class)insteadstatic booleanisSimpleType(Class<?> type)The specified type is simple type or notstatic booleanisTypeMatch(Class<?> type, String value)We only check boolean value at this moment.static Class<?>resolveClass(String className, ClassLoader classLoader)Resolve theClassby the specified name andClassLoaderstatic 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 StringsimpleClassName(Class<?> clazz)static StringtoShortString(Object obj)
-
-
-
字段详细资料
-
SIMPLE_TYPES
public static final Set<Class<?>> SIMPLE_TYPES
Simple Types including:- 从以下版本开始:
- 2.7.6
- 另请参阅:
SimpleType
-
-
方法详细资料
-
forNameWithThreadContextClassLoader
public static Class<?> forNameWithThreadContextClassLoader(String name) throws ClassNotFoundException
-
forNameWithCallerClassLoader
public static Class<?> forNameWithCallerClassLoader(String name, Class<?> caller) throws ClassNotFoundException
-
getCallerClassLoader
public static ClassLoader getCallerClassLoader(Class<?> caller)
-
getClassLoader
public static ClassLoader getClassLoader(Class<?> clazz)
get class loader- 参数:
clazz-- 返回:
- class loader
-
getClassLoader
public 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.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 anullClassLoader reference as well).- 返回:
- the default ClassLoader (never
null) - 另请参阅:
Thread.getContextClassLoader()
-
forName
public static Class<?> forName(String name) throws ClassNotFoundException
Same asClass.forName(), except that it works for primitive types.
-
forName
public static Class<?> forName(String name, ClassLoader classLoader) throws ClassNotFoundException, LinkageError
Replacement forClass.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 benull, which indicates the default class loader)- 返回:
- Class instance for the supplied name
- 抛出:
ClassNotFoundException- if the class was not foundLinkageError- if the class file could not be loaded- 另请参阅:
Class.forName(String, boolean, ClassLoader)
-
resolvePrimitiveClassName
public 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.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 class- 返回:
- the primitive class, or
nullif the name does not denote a primitive class or primitive array class
-
isPrimitive
public static boolean isPrimitive(Class<?> type)
已过时。as 2.7.6, useClass.isPrimitive()plusisSimpleType(Class)insteadThe specified type is primitive type or simple type- 参数:
type- the type to test- 返回:
-
isSimpleType
public static boolean isSimpleType(Class<?> type)
The specified type is simple type or not- 参数:
type- the type to test- 返回:
- if
typeis one element ofSIMPLE_TYPES, returntrue, orfalse - 从以下版本开始:
- 2.7.6
- 另请参阅:
SIMPLE_TYPES
-
isTypeMatch
public static boolean isTypeMatch(Class<?> type, String value)
We only check boolean value at this moment.- 参数:
type-value-- 返回:
-
getAllSuperClasses
public static Set<Class<?>> getAllSuperClasses(Class<?> type, Predicate<Class<?>>... classFilters)
Get all super classes from the specified type- 参数:
type- the specified typeclassFilters- the filters for classes- 返回:
- non-null read-only
Set - 从以下版本开始:
- 2.7.6
-
getAllInterfaces
public static Set<Class<?>> getAllInterfaces(Class<?> type, Predicate<Class<?>>... interfaceFilters)
Get all interfaces from the specified type- 参数:
type- the specified typeinterfaceFilters- the filters for interfaces- 返回:
- non-null read-only
Set - 从以下版本开始:
- 2.7.6
-
getAllInheritedTypes
public static Set<Class<?>> getAllInheritedTypes(Class<?> type, Predicate<Class<?>>... typeFilters)
Get all inherited types from the specified type- 参数:
type- the specified typetypeFilters- the filters for types- 返回:
- non-null read-only
Set - 从以下版本开始:
- 2.7.6
-
isAssignableFrom
public static boolean isAssignableFrom(Class<?> superType, Class<?> targetType)
the semantics is same asClass.isAssignableFrom(Class)- 参数:
superType- the super typetargetType- the target type- 返回:
- see
Class.isAssignableFrom(Class) - 从以下版本开始:
- 2.7.6
-
isPresent
public static boolean isPresent(String className, ClassLoader classLoader)
Test the specified class name is present in theClassLoader- 参数:
className- the name ofClassclassLoader-ClassLoader- 返回:
- If found, return
true - 从以下版本开始:
- 2.7.6
-
resolveClass
public static Class<?> resolveClass(String className, ClassLoader classLoader)
Resolve theClassby the specified name andClassLoader- 参数:
className- the name ofClassclassLoader-ClassLoader- 返回:
- If can't be resolved , return
null - 从以下版本开始:
- 2.7.6
-
isGenericClass
public static boolean isGenericClass(Class<?> type)
Is generic class or not?- 参数:
type- the target type- 返回:
- if the target type is not null or
voidor Void.class, returntrue, or false - 从以下版本开始:
- 2.7.6
-
-