package com.wuming.annotation;
import java.lang.annotation.*;
//自定义注解
public class Test03 {
//注解可以显示赋值,如果没有默认值,我们就必须给注解赋值
@MyAnnotation2(age=18,name="wuming")
public void test(){}
@MyAnnotation3("无名")
public void test2(){}
}
//定义一个注解
//Target 表示注解可以用在什么地方
//Retention 表示我们注解在什么地方还有效
//runtime>class>sources
@Retention(value = RetentionPolicy.RUNTIME)
@Target(value= {ElementType.METHOD,ElementType.TYPE})
@Documented //表示注解是否生成在JAVAdoc中
@interface MyAnnotation2{
//注解的参数:参数类型+参数名()
String name() default "";
int age();
int id() default -1;//如果默认值为-1,代表不存在
String[] schools() default{"西部开源","清华大学"};
}
@Retention(value = RetentionPolicy.RUNTIME)
@Target(value= {ElementType.METHOD,ElementType.TYPE})
@interface MyAnnotation3{
String value();
}