public class ReflectUtils extends Object
| 构造器和说明 |
|---|
ReflectUtils() |
| 限定符和类型 | 方法和说明 |
|---|---|
static Optional<Method> |
findGetterMethod(Class<?> beanType,
Field field)
find getter method
|
static Optional<Method> |
findGetterMethod(Class<?> beanType,
String fieldName)
find getter method
|
static Optional<Method> |
findMethod(Class<?> beanType,
String methodName,
int parameterCount) |
static Optional<Method> |
findSetterMethod(Class<?> beanType,
Field field)
find setter method
|
static Optional<Method> |
findSetterMethod(Class<?> beanType,
String fieldName)
find setter method
|
static @Nullable Field |
getDeclaredField(Class<?> type,
String fieldName)
Get declared field by name.
|
static Field[] |
getDeclaredFields(Class<?> type)
Get declared fields.
|
static @Nullable Method |
getDeclaredMethod(Class<?> type,
String methodName,
Class<?>... parameterTypes)
Get method by name and parameter types.
|
static Method[] |
getDeclaredMethods(Class<?> type)
Get declared methods of type.
|
static Set<Class<?>> |
getDeclaredSuperClassWithInterface(Class<?> type)
Get declared super class with interface.
|
static @Nullable Field |
getField(Class<?> type,
String fieldName)
Get field by name.
|
static Field[] |
getFields(Class<?> type)
Get fields.
|
static <T> T |
getFieldValue(Object target,
Field field)
Get field value.
|
static <T> T |
getFieldValue(Object target,
String fieldName)
Get field value.
|
static @Nullable Method |
getMethod(Class<?> type,
String methodName,
Class<?>... parameterTypes)
Get method by name and parameter types.
|
static Method[] |
getMethods(Class<?> type)
Get methods.
|
static <T> T |
invoke(Object object,
Method method,
Object... args)
Invoke method.
|
static <T> T |
invokeRaw(Object object,
Method method,
Object... args)
Invoke method.
|
static boolean |
isJdkElement(AnnotatedElement element)
Whether the
element is from jdk. |
static Object[] |
resolveMethodInvocationArguments(Method method,
Object... args)
Resolve invocation arguments of method.
|
static Map<String,Parameter> |
resolveParameterNames(ParameterNameFinder finder,
Method method)
Resolve method parameter names.
|
static <A extends Annotation,E extends AnnotatedElement> |
scanAllAnnotationFromElements(AnnotationFinder annotationFinder,
Class<A> annotationType,
E[] elements,
BiConsumer<E,A> consumer)
Get annotations for elements.
|
static <T extends AccessibleObject> |
setAccessible(T accessibleObject) |
static void |
traverseTypeHierarchy(Class<?> beanType,
Consumer<Class<?>> consumer)
Traverse type hierarchy.
|
public static <T> T invokeRaw(Object object, Method method, Object... args)
T - return typeobject - objectmethod - method to invokeargs - argumentspublic static <T> T invoke(Object object, Method method, Object... args)
T - return typeobject - objectmethod - method to invokeargs - argumentspublic static Object[] resolveMethodInvocationArguments(Method method, Object... args)
method - method to invokeargs - argumentspublic static Map<String,Parameter> resolveParameterNames(ParameterNameFinder finder, Method method)
finder - discoverermethod - methodpublic static Method[] getDeclaredMethods(Class<?> type)
type - typepublic static @Nullable Method getDeclaredMethod(Class<?> type, String methodName, Class<?>... parameterTypes)
type - typemethodName - method nameparameterTypes - parameter typespublic static Method[] getMethods(Class<?> type)
type - typeClass.getMethods()public static @Nullable Method getMethod(Class<?> type, String methodName, Class<?>... parameterTypes)
type - typemethodName - method nameparameterTypes - parameter typespublic static Optional<Method> findGetterMethod(Class<?> beanType, Field field)
beanType - bean's typefield - fieldpublic static Optional<Method> findGetterMethod(Class<?> beanType, String fieldName)
beanType - bean's typefieldName - field's namepublic static Optional<Method> findSetterMethod(Class<?> beanType, Field field)
beanType - bean's typefield - fieldpublic static Optional<Method> findSetterMethod(Class<?> beanType, String fieldName)
beanType - bean's typefieldName - field's namepublic static Optional<Method> findMethod(Class<?> beanType, String methodName, int parameterCount)
public static boolean isJdkElement(AnnotatedElement element)
element is from jdk.element - elementpublic static <A extends Annotation,E extends AnnotatedElement> void scanAllAnnotationFromElements(AnnotationFinder annotationFinder, Class<A> annotationType, E[] elements, BiConsumer<E,A> consumer)
A - annotation typeE - element typeannotationFinder - annotation finderannotationType - annotation typeelements - elementsconsumer - consumerAnnotationFinder.getAllAnnotations(java.lang.reflect.AnnotatedElement, java.lang.Class<A>)public static Set<Class<?>> getDeclaredSuperClassWithInterface(Class<?> type)
type - typepublic static void traverseTypeHierarchy(Class<?> beanType, Consumer<Class<?>> consumer)
beanType - bean typeconsumer - operation for each typepublic static @Nullable Field getDeclaredField(Class<?> type, String fieldName)
type - typefieldName - field namepublic static Field[] getDeclaredFields(Class<?> type)
type - typepublic static @Nullable Field getField(Class<?> type, String fieldName)
type - typefieldName - field namepublic static Field[] getFields(Class<?> type)
type - typepublic static <T> T getFieldValue(Object target, String fieldName)
T - field typetarget - target objectfieldName - field namepublic static <T> T getFieldValue(Object target, Field field)
T - field typetarget - target objectfield - fieldNullPointerException - thrown when field is nullpublic static <T extends AccessibleObject> void setAccessible(T accessibleObject)
Copyright © 2024. All rights reserved.