fix: 修复ClassUtil.doGetMethods最后一个参数为true时,不会提前结束遍历接口

This commit is contained in:
kamosama 2024-06-05 11:22:01 +08:00
parent 86f4358ebf
commit 9cca7e69cc

View File

@ -288,10 +288,7 @@ public class ClassUtil {
private static void doGetMethods(Class<?> clazz, List<Method> methods, Predicate<Method> predicate, boolean firstOnly) {
if (clazz == null || clazz == Object.class) {
return;
}
applyAllClass(clazz, currentClass -> {
Method[] declaredMethods = clazz.getDeclaredMethods();
if (clazz.isInterface()) {
for (Method method : declaredMethods) {
@ -313,18 +310,20 @@ public class ClassUtil {
}
}
}
// 只获取第一个并且集合不为空就结束遍历
if (firstOnly && !methods.isEmpty()) {
return;
return false;
}
Class<?>[] interfaces = clazz.getInterfaces();
for (Class<?> anInterface : interfaces) {
doGetMethods(anInterface, methods, predicate, firstOnly);
// 只获取第一个并且集合不为空就结束遍历
if (firstOnly && !methods.isEmpty()){
return false;
}
doGetMethods(clazz.getSuperclass(), methods, predicate, firstOnly);
}
return true;
});
}
private static <T> Class<T> getJdkProxySuperClass(Class<T> clazz) {