Why does Eclipse complain about @Override on interface methods?
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.
Solution 1:
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
- Browse to Java > Compiler.
- There, 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.
Solution 2:
Do as follows:
Project -> Properties -> java compiler ->
- Enable project specific settings - 'yes'
- Compiler compliance - 1.6
- generated class files and source compatibility - 1.5
Solution 3:
Check also if the project has facet. The java version may be overriden there.