interface定义接口
@interface定义annotation注解
都没有函数体。
使用方法:
implement接口名
@注解名---定义文件中有属性添属性(对应属性)
使用注解必然用到元注解@Target,@Retention,@Documented,@Inherited,元注解负责注解其他注解
@Target说明修饰对象{
ElementType.TYPE:Class, interface or enum declaration.
ElementType.FIELD:Field declaration.
ElementType.METHOD:Method declaration.
ElementType.PARAMETER:Parameter declaration.
ElementType.CONSTRUCTOR:Constructor declaration.
ElementType.LOCAL_VARIABLE:Local variable declaration.
ElementType.ANNOTATION_TYPE:Annotation type declaration.
ElementType.PACKAGE:Package declaration.
}
@Target的属性是一个数组类型,所以可以有多个值格式为{1,2,3}
@Retention定义注解被保留的时间{
RetentionPolicy.SOURCE:Annotation is only available in the source code.
RetentionPolicy.CLASS:Annotation is available in the source code and in the class file, but not at runtime. This is the default policy.
RetentionPolicy.RUNTIME:Annotation is available in the source code, the class file and is available at runtime.
}
@Documented标注为API,可以被javadoc类似工具文档化,标记注解没有成员
@Inherited标记的注解class的子类将继承为annotation。
注解参数支持的参数成员数据类型:
1:所有基本类型:int,float,long,char,byte,short,double,boolean
2:String,Class,enum,Annotation
3:以上类型对应数组
类型修饰符:只能使用public或default