继承类注解 [英] Inheriting class annotations

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

问题描述

有没有一种方法,使类从超类继承的注解?

例如

  @ApplicationException(回滚=真)
公共抽象类AbstractBeanActionException扩展异常{
    / *方法主体是简单地调用超()* /
}公共类OrderBeanException扩展AbstractBeanActionException {
    / *没有这个类必须注明呢? * /
}


解决方案

类注释不能由子类继承。

你可以做的是力的子类,使用在编译时的批注:

<一个href=\"http://today.java.net/pub/a/today/2006/06/29/validate-java-ee-annotations-with-annotation-processors.html#pluggable-annotation-processing-api\" rel=\"nofollow\">http://today.java.net/pub/a/today/2006/06/29/validate-java-ee-annotations-with-annotation-processors.html#pluggable-annotation-processing-api

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

e.g.

@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:

http://today.java.net/pub/a/today/2006/06/29/validate-java-ee-annotations-with-annotation-processors.html#pluggable-annotation-processing-api

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

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