自定义注解
Posted xd-study
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了自定义注解相关的知识,希望对你有一定的参考价值。
1.3、自定义注解
public class Test03 {
//对于没有默认值的注解必须显示赋值
// 有默认值的注解可以不再赋值
@MyAnnotation2(id = 11)
public void test(){};
//注解只有一个参数时 多用value
// 可以在配置的地方省略 value =
@MyAnnotation3("大帅锅")
public void test2(){};
}
@Target({ElementType.METHOD,ElementType.TYPE})
@Retention(value = RetentionPolicy.RUNTIME)
@interface MyAnnotation2{
//注解的参数:注解的类型 + 参数名()
int age() default 18;
String name() default "帅锅";
int id() default 0;
String[] schools() default {"北京大学","清华大学"};
}
@Target({ElementType.METHOD,ElementType.TYPE})
@Retention(value = RetentionPolicy.RUNTIME)
@interface MyAnnotation3{
String value();
}
以上是关于自定义注解的主要内容,如果未能解决你的问题,请参考以下文章