Skip to content
Advertisement

Check if Annotation is inherited

I have an annotation and three classes like this:

JavaScript

Is there any way I can determine if a present annotation is inherited or declared directly at the class?

Something like a method public boolean isInherited(Class<?> clazz, MyAnnotation annotation) that should only be called if the annotation is present.

Exptected output:

JavaScript

Advertisement

Answer

You can use getDeclaredAnnotation instead of getAnnotation:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement