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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With