一、异常现象:

自定义注解时,

@Retention和@Target都能导入进来,但是却报下列错误:

RetentionPolicy cannot be resolved to a variable

ElementType cannot be resolved to a variable

二、异常原因:

没有引入这两个类

 

三、解决方法:

手动引入RetentionPolicy和ElementType这两个类

方法一:

import java.lang.annotation.*

方法二:

import java.lang.annotation.RetentionPolicy;

import java.lang.annotation.ElementType;

 

相关文章: