一、Documented的使用
### --- 元注解@Documented
~~~ ——> 使用javadoc工具可以从程序源代码中抽取类、方法、
~~~ ——> 成员等注释形成一个和源代码配套的API帮助文档,而该工具抽取时默认不包括注解内容。
~~~ ——> @Documented用于指定被该注解将被javadoc工具提取成文档。
~~~ ——> 定义为@Documented的注解必须设置Retention值为RUNTIME。
二、编程代码
package com.yanqi.task10;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
//@Retention(RetentionPolicy.SOURCE) // 表示下面的注解在源代码中有效
//@Retention(RetentionPolicy.CLASS) // 表示下面的注解在字节码文件中有效,默认方式
@Retention(RetentionPolicy.RUNTIME) // 表示下面的注解在运行时有效
@Documented // 表示下面的注解信息可以被javadoc工具提取到API文档中,很少使用
// 若一个注解中没有任何的成员,则这样的注解叫做标记注解/标识注解
@interface MyAnnotation {
//public Direction value(); // 声明一个String类型的成员变量,名字为value 类型有要求
public String value() default "123"; // 声明一个String类型的成员变量,名字为value
public String value2();
}
三、编程代码
package com.yanqi.task10;
// 表示将标签MyAnnotation贴在Person类的代码中,使用注解时采用 成员参数名 = 成员参数值, ...
//@MyAnnotation(value = "hello", value2 = "world")
@MyAnnotation(value2 = "world")
public class Person {
private String name;
private int age;
}