Class MethodReflect
java.lang.Object
org.miaixz.bus.core.lang.reflect.method.MethodReflect
方法反射相关操作类。
- Since:
- Java 17+
- Author:
- Kimi Liu
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid清空缓存Method[]getAllMethods(Predicate<Method> predicate) 获取当前类层级结构中的所有方法。 等同于按广度优先遍历类及其所有父类与接口,并依次调用Class.getDeclaredMethods()。 返回的方法排序规则如下: 离type距离越近,则顺序越靠前; 与type距离相同,直接实现的接口方法优先于父类方法; 与type距离相同的接口,则顺序遵循接口在Class.getInterfaces()的顺序;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获取反射对象
-
Constructor Details
-
MethodReflect
构造- Parameters:
clazz- 类
-
-
Method Details
-
of
获取反射对象- Parameters:
clazz- 类- Returns:
- MethodReflect
-
getClazz
获取当前类- Returns:
- 当前类
-
clearCaches
public void clearCaches()清空缓存 -
getPublicMethods
获取当前类及父类的所有公共方法,等同于Class.getMethods()- Parameters:
predicate- 方法过滤器,null表示无过滤- Returns:
- 当前类及父类的所有公共方法
-
getDeclaredMethods
获取当前类直接声明的所有方法,等同于Class.getDeclaredMethods()- Parameters:
predicate- 方法过滤器,null表示无过滤- Returns:
- 当前类及父类的所有公共方法
-
getAllMethods
获取当前类层级结构中的所有方法。 等同于按广度优先遍历类及其所有父类与接口,并依次调用Class.getDeclaredMethods()。 返回的方法排序规则如下:- 离
type距离越近,则顺序越靠前; - 与
type距离相同,直接实现的接口方法优先于父类方法; - 与
type距离相同的接口,则顺序遵循接口在Class.getInterfaces()的顺序;
- Parameters:
predicate- 方法过滤器,null表示无过滤- Returns:
- 当前类及父类的所有公共方法
- 离
-
getMethodsDirectly
public Method[] getMethodsDirectly(boolean withSupers, boolean withMethodFromObject) throws SecurityException 获得一个类中所有方法列表,直接反射获取,无缓存 接口获取方法和默认方法,获取的方法包括:- 本类中的所有方法(包括static方法)
- 父类中的所有方法(包括static方法)
- Object中(包括static方法)
- Parameters:
withSupers- 是否包括父类或接口的方法列表withMethodFromObject- 是否包括Object中的方法- Returns:
- 方法列表
- Throws:
SecurityException- 安全检查异常
-