等于在类 - 代理和 bean 之间返回 false



我在上面的方法上有这个注释,即在Bean上,由Spring(BeanNameAutoProxy)代理。

@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

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

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

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

检查它的最佳方法是什么?

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

最新更新