在JDK1.8之后重复注解学习
1.创建一个注解类
package com.wying.demo.RepeatAnnotation;
import java.lang.annotation.*;
/**
* description:jdk1.8重复注解
* date: 2021/12/2
* author: gaom
* version: 1.0
*/
//定义注解可以使用的位置
@Target({ElementType.TYPE,ElementType.FIELD,ElementType.METHOD})
//定义注解的周期 运行时仍存在
@Retention(RetentionPolicy.RUNTIME)
public @interface Annotation01 {
//定义注解默认值
String value() default "hello word";
}
2.建一个测试类,在属性上加上刚才定义的注解编译通过
3.加上2个一样的注解是编译失败
Duplicate annotation. The declaration of 'com.wying.demo.RepeatAnnotation.Annotation01' does not have a valid java.lang.annotation.Repeatable annotation