public class ReflectionUtil extends Object
| Modifier and Type | Method and Description |
|---|---|
static boolean |
areClassesRelated(Class<?> type1,
Class<?> type2)
Determines if two classes are linked in a class hierarchy.
|
static boolean |
doesMethodBelongToType(Method method,
Class<?> type)
Checks if method belongs to a given type or super-type.
|
static List<Class<?>> |
getSuperTypesInclRoot(Class<?> rootType)
Collects all classes and interfaces a given type extends or implements.
|
static Object |
invokeMethodUnchecked(Object object,
Method method)
Calls
Method.invoke(Object, Object...) on the given method but
catches away all thrown Exceptions. |
static <T> Method |
lookupInterfaceMethod(Class<T> interfaceType,
Consumer<T> methodSpecifier) |
static Object |
primitiveTypeDefaultValue(Class<?> primitiveType)
Returnes the default value for a given primitive type, basically all
flavours of zero for the number types and
false for
boolean.class. |
public static boolean areClassesRelated(Class<?> type1, Class<?> type2)
type1 - a class or nulltype2 - the class to compare type1 with or nulltrue if both classes are identical or if one type is
base class of other. false if one of the given types
or both are null or not in a direct hierarchical
relation.public static boolean doesMethodBelongToType(Method method, Class<?> type)
method - the method to checktype - any class to search for the given methodtrue if given method is declared in given type or
one of its super types.public static Object invokeMethodUnchecked(Object object, Method method)
Method.invoke(Object, Object...) on the given method but
catches away all thrown Exceptions.object - the object the method to call on. Can be null for
static methodsmethod - the method to executeRuntimeException - wrapped around the checked exception from the method
invocationpublic static List<Class<?>> getSuperTypesInclRoot(Class<?> rootType)
rootType - the class to examineObjectpublic static <T> Method lookupInterfaceMethod(Class<T> interfaceType, Consumer<T> methodSpecifier)
public static Object primitiveTypeDefaultValue(Class<?> primitiveType)
false for
boolean.class.primitiveType - a Java primitive type like boolean.class,
int.class or float.classfalse value of type matching to given
primitiveType. If for example primitiveType is
double.class the returned value will have type
Double.class and value 0.0.