Java 使用ElementType数组会在目标注释中出错
我在其他注释(如Java 使用ElementType数组会在目标注释中出错,java,annotations,Java,Annotations,我在其他注释(如SuppressWarnings和Deprecated)中看到,它们直接使用ElementTypeenum数组,而不使用上述enum。但是当我试图在我的一个自定义注释中使用它时,它会给我一个错误。我需要将其设置为ElementType.TYPE或ElementType.FIELD,以使其正常工作。此代码有什么问题?您希望以这种方式使用该注释: 导入staticjava.lang.annotation.ElementType.* 否则,这样做: @目标({ElementType.T
SuppressWarnings
和Deprecated
)中看到,它们直接使用ElementType
enum数组,而不使用上述enum。但是当我试图在我的一个自定义注释中使用它时,它会给我一个错误。我需要将其设置为ElementType.TYPE或ElementType.FIELD,以使其正常工作。此代码有什么问题?您希望以这种方式使用该注释:
导入staticjava.lang.annotation.ElementType.*
否则,这样做:
@目标({ElementType.TYPE,ElementType.FIELD,ElementType.METHOD})是的,没错!我错过了文档中的静态部分!谢谢:)
import java.lang.annotation.ElementType.*;
import java.lang.annotation.Target;
@Target({TYPE, FIELD, METHOD})
public @interface Inter1 {
}