Java 注释“不适用于类型”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18103586/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 22:24:56  来源:igfitidea点击:

Annotations "not applicable to type"

java

提问by quarks

I am quite new to IntelliJ being a Eclipse user for many years, so I really find this error where all annotations expect for the @Overrideare showing error "not applicable to type"

多年来,我对 IntelliJ 作为 Eclipse 用户很陌生,所以我真的发现了这个错误,其中所有注释都期望@Override显示错误"not applicable to type"

E.g the @PostConstructannotation from JBoss Errai is showing this errors all around, where the import is there with no error at all.

例如,@PostConstruct来自 JBoss Errai的注释到处都显示了这个错误,其中导入完全没有错误。

How do I fix this?

我该如何解决?

Update:

更新:

E.g

例如

@PostConstruct // When hovered with the mouse pointer '@PostContruct' is not applicable to method
public void init() {
}

Screenshot: http://snag.gy/q5cW5.jpg

截图:http: //snag.gy/q5cW5.jpg

采纳答案by Joop Eggen

Looking at the definition, one sees @Targetmentioning method. So you might have imported a totally different PostConstruct annotation. Inspect the imports / go to the definition in IntelliJ.

看定义,一看就@Target提到了method。因此,您可能导入了一个完全不同的 PostConstruct 注释。 检查导入/转到 IntelliJ 中的定义。

package javax.annotation;

@Documented
@Retention(value=RUNTIME)
@Target(value=METHOD)
public @interface PostConstruct