Package org.apache.dubbo.common.utils
Class ClassUtils
java.lang.Object
org.apache.dubbo.common.utils.ClassUtils
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ObjectconvertPrimitive(Class<?> type, String value) static ObjectconvertPrimitive(FrameworkModel frameworkModel, Class<?> type, String value) static Class<?> 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<?> forNameAndTryCatch(String name) find class and don`t expect to throw exceptionstatic Class<?> forNameWithCallerClassLoader(String name, Class<?> caller) static Class<?> getAllInheritedTypes(Class<?> type, Predicate<Class<?>>... typeFilters) Get all inherited types from the specified typegetAllInterfaces(Class<?> type, Predicate<Class<?>>... interfaceFilters) Get all interfaces from the specified typegetAllSuperClasses(Class<?> type, Predicate<Class<?>>... classFilters) Get all super classes from the specified typestatic ClassLoadergetCallerClassLoader(Class<?> caller) static ClassLoaderReturn 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 String[]getDeclaredMethodNames(Class<?> tClass) get method name array.static String[]getMethodNames(Class<?> tClass) get method name array.static booleanhasMethods(Method[] methods) static booleanisAssignableFrom(Class<?> superType, Class<?> targetType) the semantics is same asClass.isAssignableFrom(Class)static booleanisGenericClass(Class<?> type) Is generic class or not?static booleanstatic booleanisPresent(String className, ClassLoader classLoader) Test the specified class name is present in theClassLoaderstatic booleanisPrimitive(Class<?> type) Deprecated.static 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<?> 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)
-
Field Details
-
Constructor Details
-
ClassUtils
public ClassUtils()
-
-
Method Details
-
forNameWithThreadContextClassLoader
public static Class<?> forNameWithThreadContextClassLoader(String name) throws ClassNotFoundException - Throws:
ClassNotFoundException
-
forNameWithCallerClassLoader
public static Class<?> forNameWithCallerClassLoader(String name, Class<?> caller) throws ClassNotFoundException - Throws:
ClassNotFoundException
-
getCallerClassLoader
-
getClassLoader
get class loader- Parameters:
clazz-- Returns:
- class loader
-
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).- Returns:
- the default ClassLoader (never
null) - See Also:
-
forName
Same asClass.forName(), except that it works for primitive types.- Throws:
ClassNotFoundException
-
forNameAndTryCatch
find class and don`t expect to throw exception- Parameters:
name-- Returns:
-
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[]").- Parameters:
name- the name of the ClassclassLoader- the class loader to use (may benull, which indicates the default class loader)- Returns:
- Class instance for the supplied name
- Throws:
ClassNotFoundException- if the class was not foundLinkageError- if the class file could not be loaded- See Also:
-
resolvePrimitiveClassName
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).- Parameters:
name- the name of the potentially primitive class- Returns:
- the primitive class, or
nullif the name does not denote a primitive class or primitive array class
-
toShortString
-
simpleClassName
-
isPrimitive
Deprecated.as 2.7.6, useClass.isPrimitive()plusisSimpleType(Class)insteadThe specified type is primitive type or simple type- Parameters:
type- the type to test- Returns:
-
isSimpleType
The specified type is simple type or not- Parameters:
type- the type to test- Returns:
- if
typeis one element ofSIMPLE_TYPES, returntrue, orfalse - Since:
- 2.7.6
- See Also:
-
convertPrimitive
-
convertPrimitive
-
isTypeMatch
We only check boolean value at this moment.- Parameters:
type-value-- Returns:
-
getAllSuperClasses
Get all super classes from the specified type- Parameters:
type- the specified typeclassFilters- the filters for classes- Returns:
- non-null read-only
Set - Since:
- 2.7.6
-
getAllInterfaces
public static Set<Class<?>> getAllInterfaces(Class<?> type, Predicate<Class<?>>... interfaceFilters) Get all interfaces from the specified type- Parameters:
type- the specified typeinterfaceFilters- the filters for interfaces- Returns:
- non-null read-only
Set - Since:
- 2.7.6
-
getAllInheritedTypes
Get all inherited types from the specified type- Parameters:
type- the specified typetypeFilters- the filters for types- Returns:
- non-null read-only
Set - Since:
- 2.7.6
-
isAssignableFrom
the semantics is same asClass.isAssignableFrom(Class)- Parameters:
superType- the super typetargetType- the target type- Returns:
- see
Class.isAssignableFrom(Class) - Since:
- 2.7.6
-
isPresent
Test the specified class name is present in theClassLoader- Parameters:
className- the name ofClassclassLoader-ClassLoader- Returns:
- If found, return
true - Since:
- 2.7.6
-
resolveClass
Resolve theClassby the specified name andClassLoader- Parameters:
className- the name ofClassclassLoader-ClassLoader- Returns:
- If can't be resolved , return
null - Since:
- 2.7.6
-
isGenericClass
Is generic class or not?- Parameters:
type- the target type- Returns:
- if the target type is not null or
voidor Void.class, returntrue, or false - Since:
- 2.7.6
-
hasMethods
-
getMethodNames
get method name array.- Returns:
- method name array.
-
isMatch
-
getDeclaredMethodNames
get method name array.- Returns:
- method name array.
-
Class.isPrimitive()plusisSimpleType(Class)instead