Package rife.tools
Class ClassUtils
java.lang.Object
rife.tools.ClassUtils
The ClassUtils class provides useful utility methods for working with Java classes.
- Since:
- 1.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic Class<?>erasedType(Class<?> context, Type type) Erases a generic type to the class that it will be at runtime.static String[]getEnumClassValues(Class klass) Returns an array of the values of the enum constants of the specified class, or null if the class is not an enum.static booleanReturns true if the specified class is a basic type.static booleanReturns true if the specified class is from the JDK.static booleanReturns true if the specified class is numeric.static booleanReturns true if the specified class is text.static TyperesolveTypeVariable(Class<?> context, TypeVariable<?> variable) Follows a type variable through the generic hierarchy of a class.static StringshortenClassName(Class klass) Returns a shortened version of the specified class name, with "$" characters replaced by underscores.static StringsimpleClassName(Class klass) Returns the simple name of the specified class without the package name.
-
Method Details
-
resolveTypeVariable
Follows a type variable through the generic hierarchy of a class.This method will for instance resolve the
Tof a supertype to the type argument that the provided class supplies for it, while continuing to follow the resolved type for as long as it is a type variable itself.- Parameters:
context- the class whose generic hierarchy provides the type argumentsvariable- the type variable to resolve- Returns:
- the resolved type; or
the type variable itself if the hierarchy doesn't provide an argument for it
- Since:
- 1.10
- See Also:
-
erasedType
Erases a generic type to the class that it will be at runtime.This method will resolve type variables through the generic hierarchy of the provided class, while a variable that can't be resolved erases to its first bound and a wildcard to its upper bound.
- Parameters:
context- the class whose generic hierarchy provides the type argumentstype- the generic type to erase- Returns:
- the erased class; or
Objectif the type can't be erased to anything more specific - Since:
- 1.10
- See Also:
-
isNumeric
Returns true if the specified class is numeric.- Parameters:
klass- the class to check- Returns:
- true if the specified class is numeric, false otherwise
- Since:
- 1.0
-
isText
Returns true if the specified class is text.- Parameters:
klass- the class to check- Returns:
- true if the specified class is text, false otherwise
- Since:
- 1.0
-
isBasic
Returns true if the specified class is a basic type.- Parameters:
klass- the class to check- Returns:
- true if the specified class is a basic type, false otherwise
- Since:
- 1.0
-
isFromJdk
Returns true if the specified class is from the JDK.- Parameters:
klass- the class to check- Returns:
- true if the specified class is from the JDK, false otherwise
- Since:
- 1.0
-
simpleClassName
Returns the simple name of the specified class without the package name.- Parameters:
klass- the class whose simple name to return- Returns:
- the simple name of the specified class
- Since:
- 1.0
-
shortenClassName
Returns a shortened version of the specified class name, with "$" characters replaced by underscores.- Parameters:
klass- the class whose name to shorten- Returns:
- a shortened version of the specified class name
- Since:
- 1.0
-
getEnumClassValues
Returns an array of the values of the enum constants of the specified class, or null if the class is not an enum.- Parameters:
klass- the class whose enum constant values to return- Returns:
- an array of the values of the enum constants of the specified class, or null if the class is not an enum
- Since:
- 1.0
-