Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/374.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用ElementType数组会在目标注释中出错_Java_Annotations - Fatal编程技术网

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 {
}