Annotation
这些标记可以再编译,类加载,运行时被读取,并执行相应处理,
Annotation可以像修饰符一样被使用,可以用于修饰包,类,构造器,方法,成员变量,参数,局部变量的声明
package exception.eee;
import java.util.ArrayList;
import java.util.List;
public class Test2 {
public static void main(String[] args) {
new TestB().test1();
@SuppressWarnings("rawtypes")
List objects = new ArrayList();
}
}
class TestA{
public void test(){
}
}class TestB extends TestA{
@Override
public void test(){
}
@Deprecated
public void test1(){
}
}
自定义annotation
@interface 关键字
public class Test2 {
public static void main(String[] args) {
@Test8(id = 40,des = ss)
String name;
new TestB().test1();
}
}
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
@Documented
@interface Test8{
public int id() default 0;
public String des() default "";
}