标签:rate ado 生成 方式 int retention 返回值 run 检查
注解元数据分为4部分分别为Target,Documented,Inherited,Retention:
/**
* @author Lean @date:2014-10-13
*/
@Target(ElementType.METHOD)
public @interface WorkInProgress {}/**
* @author Lean @date:2014-10-13
*/
public class AnnotationSample {
//当在字段中使用时:The annotation @WorkInProgress is disallowed for this location
//@WorkInProgress
private int age;
@WorkInProgress
public static boolean doSomeThing() {
// TODO Auto-generated method stub
return false;
}
}/**
* @author Lean @date:2014-10-13
*/
@WorkInProgress
public class AnnotationSample {
private int age;
@WorkInProgress
public static boolean doSomeThing() {
// TODO Auto-generated method stub
return false;
}
public static void main(String[] args) {
AnnotationSample obj=new AnnotationSample();
Class clazz=obj.getClass();
WorkInProgress progress=(WorkInProgress) clazz.getAnnotation(WorkInProgress.class);
System.out.println(clazz.getName());
if (clazz.isAnnotationPresent(WorkInProgress.class)) {
System.out.println("class Annotationed WorkInProgress!");
}
Method[] methods=clazz.getMethods();
for (Method method : methods) {
if (method.isAnnotationPresent(WorkInProgress.class)) {
System.out.println("method Annotationed WorkInProgress!");
}
}
}
}
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD,ElementType.TYPE})
@interface WorkInProgress {}
Documented>为加入注解的类书写文档,编译执行后执行javadoc的dos命令.就可以在该命令行
位置看到所生成的文档.
/**
* @author Lean @date:2014-10-13
*/
@WorkInProgress
public class AnnotationSample {
public static void main(String[] args) throws IllegalAccessException {
AnnotationSample obj=new AnnotationSample();
Class clazz=obj.getClass();
if (clazz.isAnnotationPresent(WorkInProgress.class)) {
System.out.println("class Annotationed WorkInProgress!");
}
Class childClass=AnnotationChildClass.class;
if (childClass.isAnnotationPresent(WorkInProgress.class)) {
System.out.println("child class Annotationed WorkInProgress!");
}
}
}
@Inherited
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD,ElementType.TYPE})
@interface WorkInProgress {}
class AnnotationChildClass extends AnnotationSample{
}标签:rate ado 生成 方式 int retention 返回值 run 检查
原文地址:http://www.cnblogs.com/blfbuaa/p/6884028.html