Is there something like Annotation Inheritance in java?

前端 未结 4 1997
走了就别回头了
走了就别回头了 2020-11-27 03:21

I\'m exploring annotations and came to a point where some annotations seems to have a hierarchy among them.

I\'m using annotations to generate code in the backgroun

4条回答
  •  自闭症患者
    2020-11-27 03:53

    Unfortunately, no. Apparently it has something to do with programs that read the annotations on a class without loading them all the way. See Why is it not possible to extend annotations in Java?

    However, types do inherit the annotations of their superclass if those annotations are @Inherited.

    Also, unless you need those methods to interact, you could just stack the annotations on your class:

    @Move
    @Page
    public class myAwesomeClass {}
    

    Is there some reason that wouldn't work for you?

提交回复
热议问题