0
点赞
收藏
分享

微信扫一扫

Spring工具类 -- ReflectionUtils

7dcac6528821 2022-02-17 阅读 70

Field相关操作

根据字段名称与字段类型查找Field
findField(Class<?> clazz, String name, Class<?> type)

根据字段名称查找Field
Field findField(Class<?> clazz, String name)

给指定字段设置值
setField(Field field, Object target, Object value)

获取指定字段的值
getField(Field field, Object target)

获取类中所有字段,并依次调用FieldCallback回调方法
doWithLocalFields(Class<?> clazz, FieldCallback fc)

获取类中所有字段,通过FieldFilter过滤不匹配的Feild,并依次调用FieldCallback回调方法
doWithFields(Class<?> clazz, FieldCallback fc, FieldFilter ff)

判断是否为public static final修改的字段
isPublicStaticFinal(Field field)

设置Field可访问
makeAccessible(Field field)

Method相关操作

获取当前类及其父类中所有声明的方法与接口的默认方法,再根据方法名匹配Method
findMethod(Class<?> clazz, String name)

获取当前类及其父类中所有声明的方法与接口的默认方法,再根据方法名与参数类型匹配Method
findMethod(Class<?> clazz, String name, Class<?>… paramTypes)

获取当前类及其父类中所有声明的方法与接口的默认方法, 并添加到declaredMethodsCache缓存中
getAllDeclaredMethods(Class<?> leafClass)

获取当前类及其父类中所有声明的方法与接口的默认方法,并依次调用MethodCallback回调方法
doWithLocalMethods(Class<?> clazz, MethodCallback mc)

获取当前类及其父类中所有声明的方法与接口的默认方法,通过MethodFilter过滤不匹配的Method,并依次调用MethodCallback回调方法
doWithMethods(Class<?> clazz, MethodCallback mc, MethodFilter mf)

获取当前类及其父类中所有声明的方法与接口的默认方法,再移除不是唯一的方法
getUniqueDeclaredMethods(Class<?> leafClass)

判断是否为equals()方法
isEqualsMethod(Method method)

判断是否为hashcode()方法
isHashCodeMethod(Method method)

判断是否为toString()方法
isToStringMethod(Method method)

判断是否为Object中的方法
isObjectMethod(Method method)

判断是否为通过cglib生成的代理方法
isCglibRenamedMethod(Method renamedMethod)

设置Method可访问
makeAccessible(Method method)

invoke相关操作

调用方法
invokeMethod(Method method, Object target)

根据参数调用方法
invokeMethod(Method method, Object target, Object… args)

举报

相关推荐

0 条评论