Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@Override is not allowed when implementing interface method

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)

like image 521
Nikitin Mikhail Avatar asked Mar 14 '13 06:03

Nikitin Mikhail


People also ask

Do you need @override when implementing an interface?

If you have default method in an interface, it is not mandatory to override (provide body) it in the classes that are already implementing this interface. In short, you can access the default methods of an interface using the objects of the implementing classes.

Can you override an interface method in Java?

No. Interface methods can be implemented. To overload/override a method, that method must be defined first.

Do we need to override all methods of interface?

Yes, it is mandatory to implement all the methods in a class that implements an interface until and unless that class is declared as an abstract class.

What is @override in Java?

The @Override annotation indicates that the child class method is over-writing its base class method. The @Override annotation can be useful for two reasons. It extracts a warning from the compiler if the annotated method doesn't actually override anything. It can improve the readability of the source code.


1 Answers

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.

like image 92
Bastien Jansen Avatar answered Oct 22 '22 01:10

Bastien Jansen