The interface Annotation specifies a method
Class<? extends Annotation> annotationType()
which has a zero-information1 javadoc. I wonder what it is good for. All I could find is this question, but it's not actually needed there (as the two top answers below the accepted one shows).
It allows us to use
a.annotationType().equals(MyAnnotation.class)
but
a instanceof MyAnnotation
does the same job... except when a
is an instance of a class implementing multiple annotations - but have anyone ever seen such a beast?
If a
is an instance of class A implements MyAnnotation, YourAnnotation
, then the two above tests are not equivalent, but the question is which one is better...
(*) It's like stating that getX()
returns x
.