public class MethodReflect extends Object
Constructor and Description |
---|
MethodReflect(Class<?> clazz)
构造
|
Modifier and Type | Method and Description |
---|---|
void |
clearCaches()
清空缓存
|
Method[] |
getAllMethods(Predicate<Method> predicate)
获取当前类层级结构中的所有方法。
|
Class<?> |
getClazz()
获取当前类
|
Method[] |
getDeclaredMethods(Predicate<Method> predicate)
获取当前类直接声明的所有方法,等同于
Class.getDeclaredMethods() |
Method[] |
getMethodsDirectly(boolean withSupers,
boolean withMethodFromObject)
获得一个类中所有方法列表,直接反射获取,无缓存
接口获取方法和默认方法,获取的方法包括: 本类中的所有方法(包括static方法) 父类中的所有方法(包括static方法) Object中(包括static方法) |
Method[] |
getPublicMethods(Predicate<Method> predicate)
获取当前类及父类的所有公共方法,等同于
Class.getMethods() |
static MethodReflect |
of(Class<?> clazz)
获取反射对象
|
public MethodReflect(Class<?> clazz)
clazz
- 类public static MethodReflect of(Class<?> clazz)
clazz
- 类public Class<?> getClazz()
public void clearCaches()
public Method[] getPublicMethods(Predicate<Method> predicate)
Class.getMethods()
predicate
- 方法过滤器,null
表示无过滤public Method[] getDeclaredMethods(Predicate<Method> predicate)
Class.getDeclaredMethods()
predicate
- 方法过滤器,null
表示无过滤public Method[] getAllMethods(Predicate<Method> predicate)
获取当前类层级结构中的所有方法。
等同于按广度优先遍历类及其所有父类与接口,并依次调用Class.getDeclaredMethods()
。
返回的方法排序规则如下:
type
距离越近,则顺序越靠前;type
距离相同,直接实现的接口方法优先于父类方法;type
距离相同的接口,则顺序遵循接口在Class.getInterfaces()
的顺序;predicate
- 方法过滤器,null
表示无过滤public Method[] getMethodsDirectly(boolean withSupers, boolean withMethodFromObject) throws SecurityException
withSupers
- 是否包括父类或接口的方法列表withMethodFromObject
- 是否包括Object中的方法SecurityException
- 安全检查异常Copyright © 2025. All rights reserved.