Class MethodReflect

java.lang.Object
org.miaixz.bus.core.lang.reflect.method.MethodReflect

public class MethodReflect extends Object
方法反射相关操作类。
Since:
Java 17+
Author:
Kimi Liu
  • Constructor Details

    • MethodReflect

      public MethodReflect(Class<?> clazz)
      构造
      Parameters:
      clazz - 类
  • Method Details

    • of

      public static MethodReflect of(Class<?> clazz)
      获取反射对象
      Parameters:
      clazz - 类
      Returns:
      MethodReflect
    • getClazz

      public Class<?> getClazz()
      获取当前类
      Returns:
      当前类
    • clearCaches

      public void clearCaches()
      清空缓存
    • getPublicMethods

      public Method[] getPublicMethods(Predicate<Method> predicate)
      获取当前类及父类的所有公共方法,等同于Class.getMethods()
      Parameters:
      predicate - 方法过滤器,null表示无过滤
      Returns:
      当前类及父类的所有公共方法
    • getDeclaredMethods

      public Method[] getDeclaredMethods(Predicate<Method> predicate)
      获取当前类直接声明的所有方法,等同于Class.getDeclaredMethods()
      Parameters:
      predicate - 方法过滤器,null表示无过滤
      Returns:
      当前类及父类的所有公共方法
    • getAllMethods

      public Method[] getAllMethods(Predicate<Method> predicate)
      获取当前类层级结构中的所有方法。 等同于按广度优先遍历类及其所有父类与接口,并依次调用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 - 安全检查异常