@Override is not allowed when implementing interface method

冷暖自知 提交于 2019-12-03 00:37:18

问题


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)


回答1:


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.




回答2:


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

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


Set value for Choose Language level section.


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




回答3:


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.

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


The method above is an alternative to the following approach:

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

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




回答4:


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.




回答5:


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



来源:https://stackoverflow.com/questions/15402615/override-is-not-allowed-when-implementing-interface-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!