I'm trying to make a method that returns fields that are annotated with a specific annotation.
I have one annotation (TestAnn) that I want to be a superclass for the other two (AutoSave and AutoLoad).
TestAnn:
public @interface TestAnn { boolean value() default true; } AutoSave and AutoLoad (their code are the same):
@TestAnn public @interface AutoSave { boolean value() default true; } Method to get fields:
private List<Field> getFields(Mode mode){ Class<? extends TestAnn> an; if (mode == Mode.SAVE){ an = AutoSave.class; } else if (mode == Mode.LOAD){ an = AutoLoad.class; } else{ throw new RuntimeException(); } return null; } So I tried to annotate AutoSave and AutoLoad with @TestAnn in hope that it is how inheritance works for annotations. But when I try to assign a specific annotation class to wildcard <? extends TestAnn>, the compiler says I can't do that.
So is there some sort of inheritance for annotations? If you provide code for my specific case it would be very helpful. Thanks!
getFieldsexactly?