Let's assume I have the following interface annotation @MyAnnotation
.
@Retention(RetentionPolicy.SOURCE)
@Target(ElementType.TYPE)
@interface MyAnnotation {
}
I want to implement in such a way that when someone consumes the annotation at compile time they will be told that they must extend a certain base class for example
@MyAnnotation
class Concrete extends Base {
}
The Base
class is an abstract class that contains helper methods etc. So the idea is if anyone wishes to use the annotation MyAnnotation
they would get a helpful hint to say that they must extend class Base
. Is this possible at all?
I believe the type checker framework (https://checkerframework.org/manual/) accomplishes similar aspirations to what I'm after in that it has a SubtypeOf
annotation but that seems to accept classes that extend java.lang.annotation.Annotation
. Thanks in advance as to any help with the above.