public class ReflectionUtil extends Object
| Modifier and Type | Class and Description |
|---|---|
static interface |
ReflectionUtil.TypeArgumentDelegator |
| Constructor and Description |
|---|
ReflectionUtil() |
| Modifier and Type | Method and Description |
|---|---|
static <T,U> void |
checkTypeParameterIsAssignable(Class<T> paramDefiningClass1,
String paramName1,
T object1,
Class<U> paramDefiningClass2,
String paramName2,
U object2)
Checks that the given type parameters of the given objects are compatible.
|
static <T,U,E extends Exception> |
checkTypeParametersAreEqual(Class<T> paramDefiningClass1,
String paramName1,
T object1,
Class<U> paramDefiningClass2,
String paramName2,
U object2,
Class<E> exceptionClass)
Checks that the given type parameters of the given objects are exactly equal.
|
static <T> Type |
getTypeArgument(Class<T> genericType,
String typeParameterName,
T obj) |
static Map<String,Type> |
getTypeArguments(Class<?> genericType,
Object obj)
Try to find the instantiation of all of genericTypes type parameters in objs class.
|
static boolean |
isAssignableFrom(Type type1,
Type type2) |
static <T> T |
uncheckedCast(Object o)
Perform an unchecked cast based on a type parameter.
|
public ReflectionUtil()
public static <T,U> void checkTypeParameterIsAssignable(Class<T> paramDefiningClass1, String paramName1, T object1, Class<U> paramDefiningClass2, String paramName2, U object2) throws ResourceInitializationException
T - Type of the class declaring the first type parameterU - Type of the class declaring the second type parameterparamDefiningClass1 - The class declaring the first type parameterparamName1 - The declared name of the first type parameterobject1 - The target objectparamDefiningClass2 - The class declaring the second type parameterparamName2 - The declared name of the second type parameterobject2 - The source objectResourceInitializationExceptionpublic static <T,U,E extends Exception> void checkTypeParametersAreEqual(Class<T> paramDefiningClass1, String paramName1, T object1, Class<U> paramDefiningClass2, String paramName2, U object2, Class<E> exceptionClass) throws E extends Exception
T - Type of the class declaring the first type parameterU - Type of the class declaring the second type parameterparamDefiningClass1 - The class declaring the first type parameterparamName1 - The declared name of the first type parameterobject1 - The target objectparamDefiningClass2 - The class declaring the second type parameterparamName2 - The declared name of the second type parameterobject2 - The source objectE extends Exceptionpublic static <T> Type getTypeArgument(Class<T> genericType, String typeParameterName, T obj)
public static Map<String,Type> getTypeArguments(Class<?> genericType, Object obj)
genericType - the generic supertype of objs classobj - an instantiation of a subclass of genericType. All of genericTypes type parameters
must have been instantiated in the inheritance hierarchy.public static boolean isAssignableFrom(Type type1, Type type2)
public static <T> T uncheckedCast(Object o)
T - The type to which the object should be cast.o - The object.Copyright © 2014. All rights reserved.