@Override is not allowed when implementing interface method
Asked Answered
S

7

91

I have the problem mentioned in the title. You could say that this thread duplicates another one: How do I turn off error validation for annotations in IntelliJ IDEA?

But the solution given there doesn't work. They say that I need to take the following action:

In the Project Structure | Project dialog, change the Project language Level to 6.0 - @Override in interfaces.

However, the Project language Level is 6.0 at the moment, but I still see the error.

Vic, here is the window and there is no JVM version right under Language level (unfortunately I can't post images because I have 10 reputation)

Steel answered 14/3, 2013 at 6:27 Comment(1)
I can't post images but there are no any options under "Project Language Level" but "project compiler output" which is not look like the JVM versionSteel
T
131

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.

Trimorphism answered 14/3, 2013 at 9:6 Comment(3)
yes. I have only one module, but it had the 5th language cersion. Thank youSteel
Just faced same problem. My project language level already was 6.0 but @Override annotation still was highlighted. To fix that you can open *.iml file and set LANGUAGE_LEVEL="JDK_1_6" and reload projectHarm
For anyone else finding this that is using version 2016.2.4 or higher, the menu has changed, it's now Project Structure > Modules > xxx > Language levelHerbarium
P
52

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

Peristome answered 12/7, 2015 at 6:7 Comment(0)
K
27

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

Kemppe answered 21/10, 2015 at 12:55 Comment(0)
D
15

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.

Dollop answered 17/1, 2016 at 2:22 Comment(0)
A
3

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

Ade answered 14/3, 2013 at 7:41 Comment(2)
I actually don't see any other place where I can see project language level but project-structure/projectSteel
Project Structure | Modules | <your_module> | Language LevelAde
Y
0

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>
Yasmin answered 13/6, 2020 at 23:30 Comment(0)
W
0

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

Wyck answered 8/8, 2020 at 2:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.