From 1aeb56564f38826d575e63e4e52298b9784c484e Mon Sep 17 00:00:00 2001 From: jiazhengquan <2466896229@qq.com> Date: Wed, 9 Mar 2022 11:25:52 +0800 Subject: [PATCH] =?UTF-8?q?=E9=92=88=E5=AF=B9issue#I4WUWR=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cn/hutool/core/util/ReflectUtil.java | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) 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; }