目录
- 在哪里用到了`@Documented`注解?
- 那么@Documented的作用是什么?
在哪里用到了@Documented注解?
@Documented是元注解,可以修饰其他注解。许多注解头部都有@Documented注解,例如jdk中自带的@Deprecated注解(路径是:java/lang/Deprecated.java)头部就含有这个注解:
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(value={CONSTRUCTOR, FIELD, LOCAL_VARIABLE, METHOD, PACKAGE, PARAMETER, TYPE})
public @interface Deprecated {
}
看看@Documented的源码
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.ANNOTATION_TYPE)
public @interface Documented {
}
那么@Documented的作用是什么?
如果一个注解@B,被@Documented标注,那么被@B修饰的类,生成文档时,会显示@B。如果@B没有被@Documented标准,最终生成的文档中就不会显示@B。
我们来看一些文档示例:
-
下面的图片中,类
DocumentedAnnotationTest的上方有@MyDocumentedAnnotation注解,@MyDocumentedAnnotation是被@Documented修饰的。具体代码看:Java @Documented IDEA生成文档

-
下图中,
MyTest2没有显示任何注解,原因是@B没有被Documented修饰,所以最终的文档里面,并没有显示注解@B。具体代码,看博客:java 注解示例(@Documented)

相关文章
暂无评论...


