简体   繁体   English

为什么@Documented注释具有运行时保留?

[英]Why does @Documented annotation have runtime retention?

As I know, @Documented annotation is used only by javadoc generator to generate javadocs from sources. 据我所知,@ @Documented注释仅由javadoc生成器用于从源生成javadoc。 So retention type should be SOURCE , but it's RUNTIME . 保留类型应该是SOURCE ,但它是RUNTIME Why? 为什么?

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

IMO that does not explain why @Documented needs runtime retention IMO没有解释为什么@Documented需要运行时保留

Yes, it does. 是的,它确实。 Lets say I ship a jar file without the sources. 让我们说我发送没有源的jar文件。 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. 用户可以仅使用来自类文件的信息构建适当的javadoc,因为classfile具有正确的注释,因为它们是RetentionPolicy.RUNTIME。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM