diff --git a/hutool-core/src/main/java/cn/hutool/core/util/ReflectUtil.java b/hutool-core/src/main/java/cn/hutool/core/util/ReflectUtil.java index 4f9ded9d2..dbad1e91d 100644 --- a/hutool-core/src/main/java/cn/hutool/core/util/ReflectUtil.java +++ b/hutool-core/src/main/java/cn/hutool/core/util/ReflectUtil.java @@ -663,34 +663,34 @@ public class ReflectUtil { Assert.notNull(beanClass); Method[] allMethods = null; - Class[] searchInterfaces = null, parentInterfaces = null; Class searchType = beanClass; + Class[] tempInterfaceType, interfaceType; Method[] declaredMethods; - while (searchType != null || searchInterfaces != null) { - if (searchType != null) { + if (searchType.isInterface()) { + allMethods = searchType.getDeclaredMethods(); + interfaceType = searchType.getInterfaces(); + while (ArrayUtil.isNotEmpty(interfaceType)) { + tempInterfaceType = interfaceType; + for (int i = 0; i < tempInterfaceType.length; i++) { + Class temp = tempInterfaceType[i]; + allMethods = ArrayUtil.append(allMethods, temp.getDeclaredMethods()); + if (i == 0 || ArrayUtil.isEmpty(interfaceType)) { + interfaceType = temp.getInterfaces(); + } else { + interfaceType = ArrayUtil.append(interfaceType, temp.getInterfaces()); + } + } + } + } else { + while (searchType != null) { declaredMethods = searchType.getDeclaredMethods(); if (null == allMethods) { allMethods = declaredMethods; } else { allMethods = ArrayUtil.append(allMethods, declaredMethods); } - Class[] interfaces = searchType.getInterfaces(); - for (Class element : interfaces) { - allMethods = ArrayUtil.append(allMethods, element.getDeclaredMethods()); - parentInterfaces = ArrayUtil.addAll(element.getInterfaces()); - } - searchInterfaces = parentInterfaces; - Class[] classes = searchInterfaces.length == 0 ? null : searchInterfaces; - searchInterfaces = withSuperClassMethods ? classes : null; searchType = withSuperClassMethods ? searchType.getSuperclass() : null; } - if (searchInterfaces != null) { - for (Class searchInterface : searchInterfaces) { - allMethods = ArrayUtil.append(allMethods, searchInterface.getDeclaredMethods()); - parentInterfaces = ArrayUtil.addAll(searchInterface.getInterfaces()); - } - searchInterfaces = parentInterfaces.length == 0 ? null : parentInterfaces; - } } return allMethods; }