注解引用数据类型的声明
[修饰符列表] @interface 注解类名称{ }
列如: public @interface Test{ }
注解类的使用
@注解类名称
例如: @Test;
元注解
元注解:注解类上的注解,即这个注解类上的@index进行注解;
例如: 这个注解类上的注解是元注解
@reab
public @interface Test{ }
注解可以使用在那里
注解几乎任何地方都能使用,如类,属性,方法,形参,接口类,枚举类,注解类,构造方法,静态方法。
//在类中使用
@Test
public class M1(){
// 在实例变量中使用
@Test
int i;
// 在构造方法中使用
@Test
public M1(){
}
//在实例方法中使用
@Teset
public static void sss(@Teset //在形参中使用
int i){
}
// 在静态方法中使用
@Test
public static void m mm(){
//在局部变量中使用
@Test
int i;
}
}
//在接口类中使用
@Test
abstrat interface My();
//在枚举类中使用
@Test
enum c{}
//在注解类中使用
@Test
public @interface tt(){}