且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

java中有没有像注解继承这样的东西?

更新时间:2023-12-03 14:03:16

很遗憾,没有.显然,它与读取类上的注释而不完全加载它们的程序有关.请参阅 为什么不能在 Java 中扩展注释?一个>

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?

但是,如果这些注释是 @Inherited.

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?