在实现接口方法时不允许@Override

我有标题中提到的问题。你可以说这个线程复制了另一个: 如何在 IntelliJIDEA 中关闭注释的错误验证?

但是他们给出的解决方案不起作用,他们说我需要采取以下行动:

在“项目结构 | 项目”对话框中,将接口中的“项目语言级别”更改为6.0 -@Override。

然而,目前项目语言级别是6.0,但我仍然看到错误。

Vic,这是窗口,在语言级别下没有 JVM 版本(不幸的是我不能发布图片,因为我有10个声誉)

47519 次浏览

There's also a language level for every module. Please check your module settings in the Project Structure.

If your project has multiple modules, also check that every module uses language level 6 or above, or use the project's language level (see Project Settings > Modules > xxx > Language level).

You may need to reload your project once it is modified.

At your module/project, Right click to see context menu:

enter image description here

Choose Open Module Settings or press F4. In setting windows:

enter image description here
Set value for Choose Language level section.


You also should check Project language level by this way: press Ctrl+Alt+Shift+S

enter image description here

A simpler solution - inline

  1. Put the caret on the @Override word and move the caret on the left side until the red bulb icon will appear. Then click on it.

    enter image description here

  2. Click on Set language level to 6 - Override in interfaces

    enter image description here


The method above is an alternative to the following approach:

  1. Go to File > Project Structure... or press Ctrl+Alt+Shift+S

    enter image description here

  2. Go to Project Settings > Modules > Sources > Language level and choose any level that is 6 or greater than 6.

    enter image description here

If you are using maven, add maven compiler plugin to the project's pom.xml file.

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>

This solved the issue for me.

I ran into this problem for the first time while using a multi module maven project. As other answers / IDE suggested, we need to set the language level.

Rather than changing the setting of IDE, to make the project IDE agnostic, I update the parent pom with below properties, which solved the issue.

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

In JIdea 2020.1.2 and above,

  1. Go to Project Structure [ Ctrl+Alt+Shift+S ]
  2. Select Modules sub section
  3. Select each module
  4. Under sources-section, check Language Level
  5. Change the Language Level as required

enter image description here

NOTE:

If you get below error after this change,

Error:java: Compilation failed: internal java compiler error

You have to change the target bytecode version as well.

  1. Go to Settings [ Ctrl+Alt+S ]
  2. Select Java Compiler
  3. Select module in the table
  4. Change the byte-code version to map what you selected in the previous step for language-level

enter image description here