Why does Eclipse complain about @Override on inter

2019-01-03 05:52发布

I have an existing project that uses @Override on methods that override interface methods, rather than superclass methods. I cannot alter this in code, but I would like Eclpse to stop complaining about the annotation, as I can still build with Maven.

How would I go about disabling this error?

Note: Due to project requirements, I need to compile for Java 1.5.

10条回答
我命由我不由天
2楼-- · 2019-01-03 06:04

Check also if the project has facet. The java version may be overriden there.

查看更多
唯我独甜
3楼-- · 2019-01-03 06:06

Project->Properties->java compiler->

Enable project specific settings -yes Compiler compliance - 1.6 generated class files and source compatibility - 1.5

查看更多
一夜七次
4楼-- · 2019-01-03 06:10

Project specific settings may be enabled. Select your project Project > Properties > Java Compiler, uncheck the Enable project specific settings or change Jdk 1.6 and above not forgetting the corresponding JRE.
Incase it does not work, remove your project from eclipse, delete .settings folders, .project, .classpath files. clean and build the project, import it back into eclipse and then reset your Java compiler. Clean and build your projectand eclipse. It worked for me

查看更多
狗以群分
5楼-- · 2019-01-03 06:13

Use Eclipse to search and replace (remove) all instances of "@Override". Then add back the non-interface overrides using "Clean Up".

Steps:

  1. Select the projects or folders containing your source files.
  2. Go to "Search > Search..." (Ctrl-H) to bring up the Search dialog.
  3. Go to the "File Search" tab.
  4. Enter "@Override" in "Containing text" and "*.java" in "File name patterns". Click "Replace...", then "OK", to remove all instances of "@Override".
  5. Go to "Window > Preferences > Java > Code Style > Clean Up" and create a new profile.
  6. Edit the profile, and uncheck everything except "Missing Code > Add missing Annotations > @Override". Make sure "Implementations of interface methods" is unchecked.
  7. Select the projects or folders containing your source files.
  8. Select "Source > Clean Up..." (Alt+Shift+s, then u), then "Finish" to add back the non-interface overrides.
查看更多
贪生不怕死
6楼-- · 2019-01-03 06:15

Using the @Override annotation on methods that implement those declared by an interface is only valid from Java 6 onward. It's an error in Java 5.

Make sure that your IDE projects are setup to use a Java 6 JRE, and that the "source compatibility" is set to 1.6 or greater. Open the Window > Preferences dialog, and browse to Java > Compiler. There you can set the "Compiler compliance level" to 1.6.

Remember that Eclipse can override these global settings for a specific project, so check those too.


Update:

The error under Java 5 isn't just with Eclipse; using javac directly from the command line will give you the same error. It is not valid Java 5 source code.

However, you can specify the -target 1.5 option to JDK 6's javac, which will produce a Java 5 version class file from the Java 6 source code.

查看更多
贪生不怕死
7楼-- · 2019-01-03 06:24

I understood your problem, change your jdk from your jdk to greaterthan 1.5

查看更多
登录 后发表回答