听起来您只需要使用
getMethod而不是即可
getDeclaredMethod。整个要点
getDeclaredMethod是,它
仅 查找在您要对其调用的类中声明的方法:
返回一个Method对象,该对象反映此Class对象表示的类或接口的指定声明方法。
鉴于
getMethod:
在C中搜索任何匹配方法。如果未找到匹配方法,则对C的超类递归调用步骤1的算法。
那只会找到 公共
方法。如果您使用的方法不是公开的,则应使用
getDeclaredMethod或递归层次结构中的
getDeclaredMethods每个类,自行递归该类层次结构:
Class<?> clazz = plugin.getClass();while (clazz != null) { Method[] methods = clazz.getDeclaredMethods(); for (Method method : methods) { // Test any other things about it beyond the name... if (method.getName().equals("getFile") && ...) { return method; } } clazz = clazz.getSuperclass();}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)