一、内置注解
java中三种内置注解@Deprecated 、@Override、@SuppressWarnings()
@Deprecated :用于过时的类、方法、成员变量,表示此方法不建议使用
@Override :用来修饰方法,覆盖父类方法,也就是重写
@SuppressWarnings():用来抑制编译时的警告信息
二、元注解
4种元注解: 能注解到注解上的注解,能用在其他注解上的注解。
@Target、@Retention、@Documented、@Inherited
三、自定义注解
/**
* 自定义注解
*/
@MyAnnotation2(age = 12)
public class AnnotationTest3 {
@MyAnnotation2(age = 12)
public void test1(){}
//当自定义注解只有一个,并且参数名为value,
// 引用注解时可以省略参数名
@MyAnnotation3("aaa")
public void test2(){}
}
@Target({ElementType.TYPE,ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@interface MyAnnotation2{
//注解参数 参数类型+参数名();
String username() default "";
int age();
int id() default -1;
String[] uname() default {"悟空","八戒"};
}
@Target({ElementType.TYPE,ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@interface MyAnnotation3{
String value();
}