import java.lang.annotation.*;
public class Demo03 {
@MyAnnotation2(name = "zzz",age = 20)
public void test(){
}
@MyAnnotation3("省略了value=")
public void test2(){
}
}
@Target(value = {ElementType.TYPE,ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@interface MyAnnotation2{
//定义的方法为参数
String name() default "";
int age() default 0;
String[] schools() default {"清华大学","北京大学"};
}
@Target(value = {ElementType.TYPE,ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@interface MyAnnotation3{
//默认参数必须为value才可省略
String value();
}
原文:https://www.cnblogs.com/zzzstudy/p/14613984.html