继承类注解 [英] Inheriting class annotations

查看:36
本文介绍了继承类注解的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法让类从超类继承注解?

Is there a way to make classes inherit annotations from a superclass ?

例如

@ApplicationException(rollback=true)
public abstract class AbstractBeanActionException extends Exception {
    /* method body is simply calls to super() */
}

public class OrderBeanException extends AbstractBeanActionException {
    /* does this class have to be annotated as well ? */
}

推荐答案

类注解不能被子类继承.

Class annotations can not be inherited by subclasses.

您可以做的是在编译时强制"子类使用注释:

What you can do is "force" the subclass to use the annotation at compile time:

https://community.oracle.com/docs/DOC-983563

这篇关于继承类注解的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆