为什么@Documented 注释具有运行时保留? [英] Why does @Documented annotation have runtime retention?

查看:29
本文介绍了为什么@Documented 注释具有运行时保留?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,@Documented 注释仅由 javadoc 生成器用于从源生成 javadoc.所以保留类型应该是SOURCE,但它是RUNTIME.为什么?

As I know, @Documented annotation is used only by javadoc generator to generate javadocs from sources. So retention type should be SOURCE, but it's RUNTIME. Why?

@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.ANNOTATION_TYPE)
public @interface Documented {
}

推荐答案

IMO 没有解释为什么 @Documented 需要运行时保留

IMO that does not explain why @Documented needs runtime retention

是的,确实如此.假设我发送了一个没有源的 jar 文件.用户可以仅使用来自类文件的信息构建适当的 javadoc,因为类文件具有适当的注释是因为它们是 RetentionPolicy.RUNTIME.

Yes, it does. Lets say I ship a jar file without the sources. A user can build a proper javadoc using only information from classfiles the the reason that classfile have proper annotations is becase they are RetentionPolicy.RUNTIME.

这篇关于为什么@Documented 注释具有运行时保留?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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