//抑制警告,可以修饰在类和方法上
@SuppressWarnings("all")
public class Test01 {
//@Override 重写的注解
@Override
public String toString() {
return super.toString();
}
//@Deprecated 不推荐程序员使用,但是可以使用,或者存在更好的方法
@Deprecated
public static void test(){
System.out.println("Deprecated");
}
public static void main(String[] args) {
test();
}
}
public class Test02 {
@MyAnnotation
public void test(){
}
}
//定义一个注解
//Target表示这个注解可以用在哪些地方
@Target(value = {ElementType.METHOD,ElementType.TYPE})
//Retention 表示我们注解在什么地方有效
//runtime > class > sources
@Retention(value = RetentionPolicy.SOURCE)
//Documented 表示我们的注解是否生成在JAVAdoc中
@Documented
//Inherited 子类可以继承父类的注解
@Inherited
@interface MyAnnotation{
}
元注解有四个,如下:
原文:https://www.cnblogs.com/xd-study/p/13197387.html