JDK1.5的annotation

public enum ElementType {
/** Class, interface (including annotation type), or enum declaration */
TYPE,

/** Field declaration (inlcudes enum constants) */
FIELD,

/** Method declaration */
METHOD,

/** Parameter declaration */
PARAMETER,

/** Constructor declaration */
CONSTRUCTOR,

/** Local variable declaration */
LOCAL_VARIABLE,

/** Annotation type declaration */
ANNOTATION_TYPE,

/** Package declaration */
PACKAGE
}

public enum RetentionPolicy {
/**
* Annotations are to be discarded by the compiler.
*/
SOURCE,

/**
* Annotations are to be recorded in the class file by the compiler
* but need not be retained by the VM at run time. This is the default
* behavior.
*/
CLASS,

/**
* Annotations are to be recorded in the class file by the compiler and
* retained by the VM at run time, so they may be read reflectively.
*
* @see java.lang.reflect.AnnotatedElement
*/
RUNTIME
}

The values of annotation members must be non-null compile-time constant expressions that are assignment-compatible with the declared type of the member. Allowed member types are the primitive types, String, Class, enumerated types, annotation types, and arrays of any of the above types (but not an array of arrays).

The primitive types : byte,short,char,int,long,float,double,boolean

/* 
* 元注解@Target,@Retention,@Documented,@Inherited
*
* @Target 表示该注解用于什么地方,可能的 ElemenetType 参数包括:
* ElementType.CONSTRUCTOR 构造器声明 ;
* ElementType.FIELD 域声明(包括 enum 实例) ;
* ElementType.LOCAL_VARIABLE 局部变量声明 ;
* ElementType.METHOD 方法声明 ;
* ElementType.PACKAGE 包声明 ;
* ElementType.PARAMETER 方法中的参数声明 ;
* ElementType.TYPE 类,接口(包括注解类型)或enum声明 - 即Class,Interface,Enum和Annotation;
* ElementType.ANNOTATION_TYPE annotation声明(如Document, ElementType, Retention)。
*
* @Retention 表示在什么级别保存该注解信息。可选的 RetentionPolicy 参数包括:
* RetentionPolicy.SOURCE 注解只在java文件中保留 ,将被编译器丢弃;
* RetentionPolicy.CLASS 注解在class文件中可用,但会被VM丢弃 (这是默认值);
* RetentionPolicy.RUNTIME VM将在运行期也保留注释,因此可以通过反射机制读取注解的信息。
*
* @Documented 将此注解包含在 javadoc中 。
*
* @Inherited 允许子类继承父类中的注解 。
*
*/

[quote]参考资料:
[url=http://www.iteye.com/topic/400085]JAVA 注解示例 详解[/url]
[url=http://www.iteye.com/topic/171412]Annotation学习笔记[/url]
[url=http://www.iteye.com/topic/36659?page=1]实战篇:设计自己的Annotation[/url][/quote]
另:将第三遍参考资料“[b]实战篇:设计自己的Annotation[/b]”中的DEMO整理出来,放到附件中
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值