-2

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 Answers3

2

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()) { /* ... */ }
Thomas Kläger
  • 17,754
  • 3
  • 23
  • 34
0

Maybe you can like this:

if(class.hasMethodAnnotation(Annotation.class)){}
Oliver
  • 1
  • 1
-1

Maybe you can do like this;

if (MyExampleClass.class.isAnnotationPresent(MyExampleAnnotation.class)) {
}
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – kerbermeister Feb 17 '23 at 22:09