Annotation 的作用
- 不是程序本身,可以对程序做出解释(这一点和注释没什么区别)
- 可以被别的(比如编译器)读取
Annotation 的格式
- 注解以@注释名存在,还可以加一些参数 如
@JsonIgnoreProperties(value = { "handler" })
内置注解
@Override
@Deprecated
@SuppressWarnings()
元注解
元注解的作用就是注解其他注解,java定义了四个标准meat_annotation类型,他们是被用来对其他annotation类型进行说明
public class Test1 extends Object{
@Override
public String toString() {
return super.toString();
}
public static void main(String[] args) {
text();
}
@Myinface(name = "n",age = 18,Class = {"东北大学","师范大学"})
private static void text() {
System.out.println("东北大学");
}
}
// 自定义注解
@Target({ElementType.TYPE,ElementType.METHOD})
@Retention(value = RetentionPolicy.RUNTIME)
@interface Myinface{
String name();
String[] Class();
int age();
}