From 10e2a248c7ec7792d3681ff8126b20caf4bb2533 Mon Sep 17 00:00:00 2001 From: huangchengxing <841396397@qq.com> Date: Sun, 12 Nov 2023 17:07:35 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E4=BF=AE=E5=A4=8D=E5=90=88=E6=88=90?= =?UTF-8?q?=E6=B3=A8=E8=A7=A3=E4=BC=9A=E6=97=A0=E9=99=90=E9=80=92=E5=BD=92?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E6=98=A0=E5=B0=84=E5=B1=9E=E6=80=A7=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20Gitee#I8CLBJ?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/annotation/SynthesizedAnnotationProxy.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/hutool-core/src/main/java/cn/hutool/core/annotation/SynthesizedAnnotationProxy.java b/hutool-core/src/main/java/cn/hutool/core/annotation/SynthesizedAnnotationProxy.java index 60545f9c1..00b86c95d 100644 --- a/hutool-core/src/main/java/cn/hutool/core/annotation/SynthesizedAnnotationProxy.java +++ b/hutool-core/src/main/java/cn/hutool/core/annotation/SynthesizedAnnotationProxy.java @@ -95,12 +95,13 @@ public class SynthesizedAnnotationProxy implements InvocationHandler { public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { return Opt.ofNullable(methods.get(method.getName())) .map(m -> m.apply(method, args)) - .orElseGet(() -> ReflectUtil.invoke(proxy, method, args)); + .orElseGet(() -> ReflectUtil.invoke(annotation.getAnnotation(), method, args)); } // ========================= 代理方法 ========================= void loadMethods() { + // 非用户属性 methods.put("toString", (method, args) -> proxyToString()); methods.put("hashCode", (method, args) -> proxyHashCode()); methods.put("getSynthesizedAnnotation", (method, args) -> proxyGetSynthesizedAnnotation()); @@ -114,9 +115,11 @@ public class SynthesizedAnnotationProxy implements InvocationHandler { }); methods.put("getAttributeValue", (method, args) -> annotation.getAttributeValue((String) args[0])); methods.put("annotationType", (method, args) -> annotation.annotationType()); - for (final Method declaredMethod : ClassUtil.getDeclaredMethods(annotation.getAnnotation().annotationType())) { - methods.put(declaredMethod.getName(), (method, args) -> proxyAttributeValue(method)); - } + + // 可以被合成的用户属性 + Stream.of(ClassUtil.getDeclaredMethods(annotation.getAnnotation().annotationType())) + .filter(m -> !methods.containsKey(m.getName())) + .forEach(m -> methods.put(m.getName(), (method, args) -> proxyAttributeValue(method))); } private String proxyToString() {