public final class ClassUtil extends Object
Modifier and Type | Field and Description |
---|---|
private static Map<Class<? extends Number>,Function<Number,Number>> |
NUMBER_MAPPERS
Mapping from a number class to its mapping function.
|
Modifier | Constructor and Description |
---|---|
private |
ClassUtil() |
Modifier and Type | Method and Description |
---|---|
static <N extends Number> |
convertNumber(Number number,
Class<N> targetType)
Tries to convert the given number to the given type.
|
private static <I> Type |
getActualTypeArgument(Class<? extends I> instanceClass,
Class<I> superClass,
int argumentIndex) |
static <T,I> Class<T> |
getActualTypeBinding(Class<? extends I> instanceClass,
Class<I> superClass,
int argumentIndex)
Resolves the actual binding of a generic type that was specified in a superclass and bound in a subclass.
|
static <T,I> Class<T> |
getActualTypeBinding(Class<? extends I> instanceClass,
Class<I> declaringClass,
Type attributeType)
Resolves the actual binding of a generic type to a specific class by inspecting type variables in the declaring
class and the (sub)class of the object.
|
static String |
getCallerMethod()
Resolves the name of the method that called the caller of this method.
|
static String |
getCallerMethod(Class<?> callerClass)
Resolves the name of the method that called the caller of this method.
|
public static <N extends Number> N convertNumber(Number number, Class<N> targetType)
number
- the number that we havetargetType
- the type that we needIllegalArgumentException
- if the target type is not a common number typeprivate static <I> Type getActualTypeArgument(Class<? extends I> instanceClass, Class<I> superClass, int argumentIndex)
public static <T,I> Class<T> getActualTypeBinding(Class<? extends I> instanceClass, Class<I> superClass, int argumentIndex)
instanceClass
- the implementing classsuperClass
- the superclass or interface which specifies the generic type variableargumentIndex
- the index of the type variable in the superclass definition (0 = the first type variable)public static <T,I> Class<T> getActualTypeBinding(Class<? extends I> instanceClass, Class<I> declaringClass, Type attributeType)
instanceClass
- the class that implements the object and may contain the binding of the type parametersdeclaringClass
- the class that declared the attributeattributeType
- the return type, parameter type or field type of the attribute that may contain references to type
parameterspublic static String getCallerMethod()
Copyright © 2022 fastnate.org. All rights reserved.