How do you know if a class is an annotation

60 Views Asked by At

how to juge a class is an annotation,

  • How do you know if a class is an annotation

Is there a good Samaritan out there,,,,,,, how to juge a class is an annotation

3

There are 3 best solutions below

2
Oliver On

Maybe you can like this:

if(class.hasMethodAnnotation(Annotation.class)){}
1
jetbrain_icin icin On

Maybe you can do like this;

if (MyExampleClass.class.isAnnotationPresent(MyExampleAnnotation.class)) {
}
0
Thomas Kläger On

If you have the source code: an annotation is declard as

@interface MyAnnotation { /* ... */ }

If you have some class object:

// Class<?> myClass = MyAnnotation.class;
if (myClass.isAnnotation()) { /* ... */ }