1.什么是注解
package top.ltyzqhh.Annotation;
import java.util.ArrayList;
import java.util.List;
//什么是注解
public class Test01 extends Object{
//@Override 重写注解
@Override
public String toString() {
return super.toString();
}
//@Deprecated 不推荐程序员使用,但是可以使用,或者存在更好的方式
@Deprecated
public static void test(){
System.out.println("Deprecated");
}
//SuppressWarnings 镇压警告
@SuppressWarnings("all")
public void test02(){
List list=new ArrayList();
}
public static void main(String[] args) {
test();
}
}
2.元注解
package top.ltyzqhh.Annotation;
import java.lang.annotation.*;
//测试元注解
public class Test03 {
@MyAnnotation
public void test(){
}
}
//定义一个注解
//表是我们的注解可以用在哪些地方
@Target(value = {ElementType.METHOD,ElementType.TYPE})
//Retention 表示我们的注解在什么地方有效,
//runtime>class>sources
@Retention(value = RetentionPolicy.RUNTIME)
//Documented 表示是否将我们的注解生成在Javadoc中
@Documented
//Inherited 表示子类可以继承父类的注解
@Inherited
@interface MyAnnotation{
}