public final class ReflectionUtils
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static interface |
ReflectionUtils.Predicate<T> |
| Modifier and Type | Field and Description |
|---|---|
static ReflectionUtils.Predicate<java.lang.reflect.Method> |
NOT_PRIVATE |
static java.lang.reflect.Method |
OBJECT_EQUALS |
static java.lang.reflect.Method |
OBJECT_FINALIZE |
static java.lang.reflect.Method |
OBJECT_HASHCODE |
static java.lang.reflect.Method |
OBJECT_TOSTRING |
private static java.util.Map<java.lang.Class<?>,java.lang.Class<?>> |
primitiveToWrapperType |
| Modifier | Constructor and Description |
|---|---|
private |
ReflectionUtils() |
| Modifier and Type | Method and Description |
|---|---|
private static java.lang.reflect.Method |
findDefaultMethod(java.lang.Class<?> searchedClass,
java.lang.String name,
java.lang.Class<?>[] paramTypes) |
static java.lang.reflect.Method |
findMethod(java.lang.Class<?> clazz,
java.lang.String name,
ReflectionUtils.Predicate<java.lang.reflect.Method> filter)
Attempt to find a
Method on the supplied class with the supplied
name and no parameters. |
static java.lang.reflect.Method |
findMethod(java.lang.Class<?> clazz,
java.lang.String name,
ReflectionUtils.Predicate<java.lang.reflect.Method> filter,
java.lang.Class<?>... paramTypes)
Attempt to find a
Method on the supplied class with the supplied
name and parameter types. |
static <T> java.lang.reflect.Constructor<T> |
getConstructor(java.lang.Class<T> clazz,
java.lang.Object... objs)
Returns a constructor that contains
objs as arguments. |
static java.lang.reflect.Method |
getDeclaredMethod(java.lang.Class<?> clazz,
java.lang.String name,
java.lang.Class<?>... paramTypes)
Basically calls getDeclaredMethod on a Class but wraps the
NoSuchMethodException into a Runtime.
|
static boolean |
isClassAvailable(java.lang.String className)
Tells if a class is available in the classpath
|
static boolean |
isDefaultMethod(java.lang.reflect.Method method) |
private static boolean |
isMatchingConstructor(java.lang.reflect.Constructor<?> classConstructor,
java.lang.Object... objs)
Returns true if objects in
objs are eligible to be passed to
classConstructor. |
private static java.lang.Class<?> |
wrapPrimitive(java.lang.Class<?> parameterType)
Given a primitive type, returns its boxed equivalent.
|
public static final ReflectionUtils.Predicate<java.lang.reflect.Method> NOT_PRIVATE
private static final java.util.Map<java.lang.Class<?>,java.lang.Class<?>> primitiveToWrapperType
public static final java.lang.reflect.Method OBJECT_EQUALS
public static final java.lang.reflect.Method OBJECT_HASHCODE
public static final java.lang.reflect.Method OBJECT_TOSTRING
public static final java.lang.reflect.Method OBJECT_FINALIZE
public static java.lang.reflect.Method findMethod(java.lang.Class<?> clazz,
java.lang.String name,
ReflectionUtils.Predicate<java.lang.reflect.Method> filter)
Method on the supplied class with the supplied
name and no parameters. Searches all superclasses up to
Object. The filter is used to ignore some kind of methods the caller doesn't want to see returned. In this case
they are totally ignored and can't clash with a non-ignored one to cause ambiguity.
Returns null if no Method can be found.
clazz - the class to introspectname - the name of the methodfilter - tells what methods to ignore in the researchnull if none foundpublic static java.lang.reflect.Method findMethod(java.lang.Class<?> clazz,
java.lang.String name,
ReflectionUtils.Predicate<java.lang.reflect.Method> filter,
java.lang.Class<?>... paramTypes)
Method on the supplied class with the supplied
name and parameter types. Searches all superclasses up to
Object. The filter is used to ignore some kind of methods the caller doesn't want to see returned. In this case
they are totally ignored and can't clash with a non-ignored one to cause ambiguity.
Returns null if no Method can be found.
clazz - the class to introspectname - the name of the methodfilter - tells what methods to ignore in the researchparamTypes - the parameter types of the method (may be null to
indicate any signature)null if none foundprivate static java.lang.reflect.Method findDefaultMethod(java.lang.Class<?> searchedClass,
java.lang.String name,
java.lang.Class<?>[] paramTypes)
public static <T> java.lang.reflect.Constructor<T> getConstructor(java.lang.Class<T> clazz,
java.lang.Object... objs)
throws java.lang.NoSuchMethodException
objs as arguments.
We could not do something like clazz.getConstructor(objs.class())
because that would require casting all the passed arguments to the exact
parameter types of the desired constructor.
T - type of the class searchedclazz - class on which we are searching the constructorobjs - list of arguments of the constructorobjsjava.lang.NoSuchMethodException - when the constructor with args does not exist or is
ambiguousprivate static boolean isMatchingConstructor(java.lang.reflect.Constructor<?> classConstructor,
java.lang.Object... objs)
objs are eligible to be passed to
classConstructor.private static java.lang.Class<?> wrapPrimitive(java.lang.Class<?> parameterType)
int, returns Integer.parameterType - the primitive typepublic static java.lang.reflect.Method getDeclaredMethod(java.lang.Class<?> clazz,
java.lang.String name,
java.lang.Class<?>... paramTypes)
clazz - class on which the getDeclaredMethod is calledname - method nameparamTypes - method parameterspublic static boolean isClassAvailable(java.lang.String className)
className - full class namepublic static boolean isDefaultMethod(java.lang.reflect.Method method)