【问题标题】:Equals returns false between classes - proxy and beanEquals 在类之间返回 false - 代理和 bean
【发布时间】:2016-02-08 21:31:44
【问题描述】:

我在上面的方法上有这个注解,它是在一个由 Spring (BeanNameAutoProxy) 代理的 bean 上。

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)  
public @interface CustomAnnotation{
     public boolean enabled() default true;
 }

CustomAnnotation.class.getClass() 给我interface mypackage.CustomAnnotation

methodInvocation.getMethod().getAnnotations()[0].getClass() 给我@mypackage.CustomAnnotation

所以 equals 在同一注解的两个 getClass() 方法之间返回 false。

我有List<Class> annotationClassList,我添加到列表CustomAnnotation.getClass()

我想检查methodInvocation.getMethod().getAnnotations()[0].getClass() 是否在列表中。

最好的检查方法是什么?

【问题讨论】:

    标签: java spring annotations


    【解决方案1】:

    CustomAnnotation.class.equals(methodInvocation.getMethod().getAnnotations()[0]) 应该可以解决问题。 CustomAnnotation.class.getClass() 应该返回 java.lang.Class

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-18
      • 2016-07-06
      • 2015-09-18
      相关资源
      最近更新 更多