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

Jof*_*sey 5 java annotations javadoc

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

@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.ANNOTATION_TYPE)
public @interface Documented {
}
Run Code Online (Sandbox Code Playgroud)

小智 0

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

是的,它确实。假设我发送了一个没有源代码的 jar 文件。用户可以仅使用类文件中的信息构建正确的 javadoc,类文件具有正确注释的原因是它们是 RetentionPolicy.RUNTIME。