内置注解
@Override
:方法重写,加上后能在编译器进行检查@Deprecated
:不建议使用的方法或类,表示已废弃@SuppressWarnings
:抑制编译时的警告信息@SuppressWarnings("all")
@SuppressWarnings("unchecked")
@SuppressWarnings(value={"unchecked","deprecation"})
元注解
负责注解其他注解
@Target
:描述注解的范围@Retention
:需要在什么级别下保存注解信息,描述注解的生命周期(SOURCE < CLASS < RUNTIME)@Document
:说明该注解将被包含在javadoc中@Inherited
:说明子类可以继承父类中的注解
public class AnnotationTest {
@MyAnnotation(name = "测试")
public void test() {}
}
@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@interface MyAnnotation {
// 注解的参数:参数类型 参数名()
String name();
int age() default 20;
}