@Typed public abstract class ReflectionUtils extends Object
Modifier and Type | Method and Description |
---|---|
static int |
calculateHashCodeOfAnnotation(Annotation annotation,
boolean skipNonbindingMembers) |
static int |
calculateHashCodeOfType(Type type)
We need this method as some weird JVMs return 0 as hashCode for classes.
|
static Type[] |
getActualTypeArguments(Class<?> clazz)
Gets the actual type arguments of a class
|
static Type[] |
getActualTypeArguments(Type type)
Gets the actual type arguments of a Type
|
static Set<Field> |
getAllDeclaredFields(Class<?> clazz)
Get all the declared fields on the class hierarchy.
|
static Set<Method> |
getAllDeclaredMethods(Class<?> clazz)
Get all the declared methods on the class hierarchy.
|
static <T> Class<T> |
getRawType(Type type)
Extract the raw type, given a type.
|
static boolean |
hasSameSignature(Method a,
Method b) |
static <T> T |
invokeMethod(Object instance,
Method method,
Class<T> expectedReturnType,
boolean setAccessible,
Object... args)
Invoke the method on the instance, with any arguments specified, casting
the result of invoking the method to the expected return type.
|
static boolean |
isAbstract(Method method)
Checks if a method is abstract
|
static boolean |
isArrayType(Class<?> rawType)
Checks if raw type is array type
|
static boolean |
isFinal(Class<?> clazz)
Checks if class is final
|
static boolean |
isFinal(Member member)
Checks if member is final
|
static boolean |
isPackagePrivate(int mod) |
static boolean |
isParameterizedType(Class<?> type)
Checks if type is parameterized type
|
static boolean |
isParameterizedTypeWithWildcard(Class<?> type) |
static boolean |
isPrimitive(Type type) |
static boolean |
isPrivate(Member member)
Checks if member is private
|
static boolean |
isSerializable(Class<?> clazz)
Check if a class is serializable.
|
static boolean |
isStatic(Class<?> type)
Checks if type is static
|
static boolean |
isStatic(Member member)
Checks if member is static
|
static boolean |
isTransient(Member member) |
static Field |
tryToFindDeclaredField(Class<?> clazz,
String name)
Search the class hierarchy for a field with the given name.
|
public static Set<Field> getAllDeclaredFields(Class<?> clazz)
clazz
- The class to searchpublic static Field tryToFindDeclaredField(Class<?> clazz, String name)
clazz
- The class to searchname
- The name of the field to search forpublic static Set<Method> getAllDeclaredMethods(Class<?> clazz)
clazz
- The class to searchpublic static <T> T invokeMethod(Object instance, Method method, Class<T> expectedReturnType, boolean setAccessible, Object... args)
Invoke the method on the instance, with any arguments specified, casting the result of invoking the method to the expected return type.
This method wraps Method.invoke(Object, Object...)
, converting the
checked exceptions that Method.invoke(Object, Object...)
specifies
to runtime exceptions.
If instructed, this method attempts to set the accessible flag of the method in a
PrivilegedAction
before invoking the method.
setAccessible
- flag indicating whether method should first be set as
accessiblemethod
- the method to invokeinstance
- the instance to invoke the methodargs
- the arguments to the methodRuntimeException
- if this Method
object enforces Java
language access control and the underlying method is
inaccessible or if the underlying method throws an exception or
if the initialization provoked by this method fails.IllegalArgumentException
- if the method is an instance method and
the specified instance
argument is not an instance
of the class or interface declaring the underlying method (or
of a subclass or implementor thereof); if the number of actual
and formal parameters differ; if an unwrapping conversion for
primitive arguments fails; or if, after possible unwrapping, a
parameter value cannot be converted to the corresponding formal
parameter type by a method invocation conversion.NullPointerException
- if the specified instance
is
null and the method is an instance method.ClassCastException
- if the result of invoking the method cannot be
cast to the expectedReturnTypeExceptionInInitializerError
- if the initialization provoked by this
method fails.Method.invoke(Object, Object...)
public static <T> Class<T> getRawType(Type type)
T
- the typetype
- the type to extract the raw type frompublic static boolean isSerializable(Class<?> clazz)
clazz
- The class to checkVoid
public static boolean isFinal(Class<?> clazz)
clazz
- The class to checkpublic static boolean isFinal(Member member)
member
- The member to checkpublic static boolean isPrivate(Member member)
member
- The member to checkpublic static boolean isPackagePrivate(int mod)
public static boolean isStatic(Class<?> type)
type
- Type to checkpublic static boolean isStatic(Member member)
member
- Member to checkpublic static boolean isTransient(Member member)
public static boolean isAbstract(Method method)
public static Type[] getActualTypeArguments(Class<?> clazz)
clazz
- The class to examinepublic static Type[] getActualTypeArguments(Type type)
type
- The type to examinepublic static boolean isArrayType(Class<?> rawType)
rawType
- The raw type to checkpublic static boolean isParameterizedType(Class<?> type)
type
- The type to checkpublic static boolean isParameterizedTypeWithWildcard(Class<?> type)
public static boolean isPrimitive(Type type)
public static int calculateHashCodeOfAnnotation(Annotation annotation, boolean skipNonbindingMembers)
public static int calculateHashCodeOfType(Type type)
Copyright © 2020 The Apache Software Foundation. All rights reserved.