您的位置:首页 > 编程语言 > Java开发

java注释

2013-09-29 23:07 204 查看
myAnnotation

package com.wzh.test;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface myAnnotation {

String name() default "abc";

//默认的值
String value();
}

使用:

package com.wzh.test;

@myAnnotation("v")
public class Student {

public static void main(String[] args) {
// 如何通过反射获取注解信息
Class<?> c = Student.class;
myAnnotation ma = c.getAnnotation(myAnnotation.class);
System.out.println(ma);

boolean flag= c.isAnnotationPresent(myAnnotation.class);
System.out.println(flag);

System.out.println(ma.value());
System.out.println(ma.name());
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: