michealAtmi February 2016

Equals returns false between classes - proxy and bean

I have this annotation above method, that is on a bean, which is proxied by Spring (BeanNameAutoProxy).

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

CustomAnnotation.class.getClass() gives me interface mypackage.CustomAnnotation

methodInvocation.getMethod().getAnnotations()[0].getClass() gives me @mypackage.CustomAnnotation

So equals returns false between two getClass() methods of the same annotation.

I have List<Class> annotationClassList, I added to the list CustomAnnotation.getClass();

I want to check if methodInvocation.getMethod().getAnnotations()[0].getClass() is on the list.

What is the best way to check it?

Answers


Thorsten Schiffer February 2016

CustomAnnotation.class.equals(methodInvocation.getMethod().getAnnotations()[0]) should do the trick. CustomAnnotation.class.getClass() should retun java.lang.Class

Post Status

Asked in February 2016
Viewed 3,944 times
Voted 14
Answered 1 times

Search




Leave an answer