This is regarding use of annotations in Java. I associated an annotation with a method while declaring it in the interface. While implementing, how can I ensure that the annotation is carried along with @Override annotation and if not, it should throw a compilation error?
Thanks.
You can’t.
You need to write some code to do this (either on your applciation load time, or using apt)
I had the same scenario, and created an annotation of my own:
and applied it to other annotations, like:
Imporant: have in mind that
@Overridehas a compile-time (SOURCE) retention policy, i.e. it isn’t available at run-time.