Annotation

来源:互联网 发布:写字板软件下载 编辑:程序博客网 时间:2024/04/28 08:05

Annotation 注解

public interfaceAnnotation

a)  Annotation是一个接口

b)  所有使用@interface 自定义的注解都继承于java.lang.annotation.Annotation

c)  如果有接口extends Annotation,那么该接口依旧是接口,这和注解没有任何关系

public interface Personextends Annotation 定义接口

public @interface Person 定义注解

 

public @interface Override

public @interfaceSuppressWarnings

public @interfaceDeprecated

public @interfaceRetention


一个方法可以被多个注解修饰

一个注解也可以被多个注解修饰

 

Retention 修饰注解 指明注解保持的时间

enum RetentionPolicy

{

     SOURCE,CLASS,RUNTIME;

}

SOURCE 注解信息保留在源文件中

CLASS 注解信息保留在class文件中

RUNTIME 注解信息可以保留在VM中,反射读取

public @interfaceRetention

{

     [enum 类型]RetentionPolicy value;

}

@Retention(value =RetentionPolicy.SOURCE)

public @interfaceOverride...

 

@Retention(value =RetentionPolicy.SOURCE)

public @interface SuppressWarnings...

@Retention(value =RetentionPolicy.RUNTIME)

public @interfaceDeprecated...

 

@Retention(value =RetentionPolicy.RUNTIME)

public @interfaceRetention...

public enumRetentionPolicy ...

 


0 0