public class ReflectHelper extends Object
| 限定符和类型 | 类和说明 |
|---|---|
static class |
ReflectHelper.MethodParameter |
| 限定符和类型 | 字段和说明 |
|---|---|
static Function<Class<?>,Boolean> |
ALL_OBjECT |
static Function<Class<?>,Boolean> |
ALL_OBJECT_EXCEPT_JAVA_SDK |
static Function<Class<?>,Boolean> |
NOT_NULL |
| 限定符和类型 | 方法和说明 |
|---|---|
static <S,T extends S> |
extendInterface(T o,
Object... objects) |
static void |
foreachClass(Consumer<Class<?>> processor,
Function<String,Boolean> filter,
String... packages) |
static Field[] |
getAllDeclaredFields(Class<?> clz) |
static Field[] |
getAllDeclaredFields(Class<?> clz,
Function<Class<?>,Boolean> decision) |
static Class<?>[] |
getAllInterfaces(Class<?> clz) |
static <T extends Annotation> |
getAnnotation(Class<T> annotationClass,
AnnotatedElement... elements) |
static <T extends Annotation> |
getAnnotation(Class<T> annotationClass,
AnnotatedElement element,
Set<AnnotatedElement> checked) |
static Method |
getLambdaMethod(Object lambda)
获取lambda表达式实例的方法签名,方法来源:https://zhuanlan.zhihu.com/p/151438084
原理,在lambda实例的class(isSynthetic)中找到对应的方法,因为lambda表达式是单一方法的实例,所以能够找到的应该是有且仅有的一个方法
|
static String |
getParameterName(Constructor<?> executable,
int index) |
static String |
getParameterName(Method method,
int index) |
static String |
getParameterName(Object executable,
int index,
String prefix) |
static Object |
invoke(Object obj,
Method method,
Object[] args) |
static boolean |
isAssignable(Class<?> from,
Class<?> to) |
static boolean |
isMatch(Type instanceType,
Type serviceType) |
static <T> T |
throwExceptionObject(Class<T> interfaceClass,
Function<Method,Throwable> function) |
static <T> T |
throwExceptionObject(Class<T> interfaceClass,
Supplier<Throwable> supplier) |
static String |
typeToCodeStr(Type type) |
public static <T extends Annotation> T getAnnotation(Class<T> annotationClass, AnnotatedElement element, Set<AnnotatedElement> checked)
public static <T extends Annotation> T getAnnotation(Class<T> annotationClass, AnnotatedElement... elements)
public static Method getLambdaMethod(Object lambda) throws ReflectiveOperationException
原理,在lambda实例的class(isSynthetic)中找到对应的方法,因为lambda表达式是单一方法的实例,所以能够找到的应该是有且仅有的一个方法
lambda - lambda instanceReflectiveOperationException - exceptionpublic static String getParameterName(Constructor<?> executable, int index)
public static Field[] getAllDeclaredFields(Class<?> clz, Function<Class<?>,Boolean> decision)
public static Object invoke(Object obj, Method method, Object[] args) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException
public static void foreachClass(Consumer<Class<?>> processor, Function<String,Boolean> filter, String... packages)
public static <T> T throwExceptionObject(Class<T> interfaceClass, Supplier<Throwable> supplier)
public static <T> T throwExceptionObject(Class<T> interfaceClass, Function<Method,Throwable> function)
public static <S,T extends S> S extendInterface(T o,
Object... objects)
S - 必须是接口T - extends So - objectobjects - 需要扩展出来的对象,只扩展接口Copyright © 2022. All rights reserved.