Remove @Override annotation error in Java8
Solution 1
Please let me know why is the error coming or help me fix it?
This can happen when the latest class files are not being generated i.e., the override method signature is not matching because the class files are still referring to old. So, ensure that the project is built properly and the latest class files are being generated.
In eclipse, Project (at the top bar) -> clean and check whether the latest class files are being generated (in the project/target/classes
folder or any other which you have configured). Also, ensure that there are no other errors in the project which might prevent the class files generation. You can also look here on why project can't be built.
Solution 2
Looks like your IDE Eclipse is having a JRE system library prior to 1.6 configured in its Java Build Path. And to rectify this you need to configure your Workspace default JRE (JDK1.8.0_xx)'s system library instead of the 1.5 one. To do this you should goto your
project> Build Path> Configure Build Path> Java Build Path > Libraries tab
Here, verify the JRE system library. Most probably this will be 1.5 because which this error is occurring. Now, click on Add Library Select Library type -> JRE System Library -> Next
Select Workspace default JRE (jdk 1.8.0_xx) assuming that you have installed this. Otherwise select other installed jre on your system. Click Finish. Your JRE 1.8 should be added to JRE system library. Now remove JRE 1.5 from the build path and click Apply. Check your Java Compiler JDK compliance level is still 1.8 and then do a clean build. This should resolve the issue.
Solution 3
You have the "use compliance from the execution environment on Java Build Path" checkbox checked. You need to make certain you have selected a 1.8 JRE in your Build Path definition. 1.5 JRE will produce this error.
Comments
-
tourist almost 2 years
I created the following interface with a single method:
public interface Greeting { public void perform(); }
I was trying to pass an instance of the interface to the greet() method.
public class Greeter { public void greet(Greeting greeting){ greeting.perform(); } public static void main(String[] args) { Greeter greeter=new Greeter(); } }
I created an implementation of Greeting Interface:
public class HelloWorldGreeting implements Greeting { @Override public void perform() { System.out.println("Hello World"); } }
I was getting the error(The method perform() of type HelloWorldGreeting must override or implement a supertype method) with a quick fix as "Remove @Override annotation"
I also checked compiler configuration. It's 1.8 only.
Please let me know why is the error coming or help me fix it. Thanks in advance.