Annotation介绍@interface
来源:互联网 发布:素描绘画软件 编辑:程序博客网 时间:2024/05/04 06:20
Annotation是继承自Java.lang.annotation.Annotation的类,用于向程序分析工具或虚拟机提供package class field methed 等方面的信息,它和其他类没什么区别,除了使用方式.
Annotation的一般形式是 :
我认为和它等价的java类为:
Annotation的使用方法和Bean的比较:
@interface实际上是继承了java.lang.annotation.Annotation,所以定义annotation时不能继承其他annotation或interface.
java.lang.annotation.Retention告诉编译器如何对待 Annotation,使用Retention时,需要提供java.lang.annotation.RetentionPolicy的枚举值.
.
java.lang.annotation.Target告诉编译器Annotation使用在哪些地方,使用需要指定java.lang.annotation.ElementType的枚举值.
java.lang.annotation.Documented用于指定该Annotation是否可以写入javadoc中.
java.lang.annotation.Inherited用于指定该Annotation用于父类时是否能够被子类继承.
如
java.lang.reflect.AnnotatedElement接口提供了四个方法来访问Annotation
Class、Constructor、Field、Method、Package等都实现了该接口,可以通过这些方法访问Annotation信息,前提是要访问的Annotation指定Retention为RUNTIME.
Java内置的annotation有Override Deprecated SuppressWarnings.
Override只用于方法,它指明注释的方法重写父类的方法,如果不是,则编译器报错.
Deprecated指明该方法不建议使用
SuppressWarnings告诉编译器:我知道我的代码没问题,你不用吓我了,我不怕的^_^
这些都是Mark Annotation,名称本身就包含了要提供的信息,不需要额外提供.
转自:http://www.javaeye.com/topic/171412
- Annotation介绍@interface
- Annotation介绍@interface
- Annotation介绍@interface
- Annotation 介绍@interface
- Annotation介绍@interface
- Java注解Annotation介绍 @interface
- Annotation PK Interface
- Annotation vs Interface
- Annotation 介绍
- Annotation介绍
- Annotation介绍
- interface介绍
- Annotation VS. XML VS. interface
- 侵入,无侵入? Annotation vs Interface
- 侵入,无侵入? Annotation vs Interface
- 侵入,无侵入? Annotation vs Interface
- Java annotation 自定义注释@interface的用法
- Java annotation 自定义注释@interface的用法
- 解决:Error: Could not find gradle wrapper within android sdk. Might need to update yo ur Android SDK..
- redis学习记录04-redis排序命令与设置键过期命令
- 教你配电脑·入门
- Yii2汉字转拼音类
- 求最大公约数和最小公倍数
- Annotation介绍@interface
- 关于maven学习资料
- linux和windows下安装python拓展包及requirement.txt安装类库
- nginx阻止用户代理
- C++中虚析构函数的作用
- linux 中线程的查看方式
- Spring笔记
- 基础CSS学习二
- c语言求x的n次方