1

I'm having an annoying issue with IntelliJ where it's putting yellow warning lines under my @Override annotations when implementing an interface?

enter image description here

Any ideas why?

Cheers.

EDIT: Error reads "'@Override not applicable to method'".

Interface decleration:

public interface Material {

public long getID();

public String getMaterialCode();

public String getMaterialShortName();

public String getMaterialLongName();

}

class deceleration:

public class StandardMaterial implements Material {

private long id;
private String materialCode;
private String materialShortName;
private String materialLongName;

public long getID() {
    return id;
}

@Override
public String getMaterialCode() {
    return materialCode;
}

@Override
public String getMaterialShortName() {
    return materialShortName;
}

@Override
public String getMaterialLongName() {
    return materialLongName;
}

}

(Using Java 8)

enter image description here

Nick
  • 1,269
  • 5
  • 31
  • 45
  • 1
    what is intellij message when put mouse on @override? intellij does not show unnecessary errors. it should be a problem in your code – Blue Ocean Jun 17 '14 at 09:52
  • 1
    Is your project set to Java 1.5 compatibility, by any chance? – Robby Cornelissen Jun 17 '14 at 09:56
  • what message it shows on mouse hover on `@Override` ? – user3145373 ツ Jun 17 '14 at 09:57
  • @RobbyCornelissen I'm using language level 7.0 – Nick Jun 17 '14 at 10:08
  • @NimChimpsky Already using java 8! – Nick Jun 17 '14 at 10:08
  • @Ash um, I bet your not. Are you sure intellij is using the correct compiler – NimChimpsky Jun 17 '14 at 10:08
  • @BlueOcean updated to show error – Nick Jun 17 '14 at 10:09
  • This is already asked, check out: http://stackoverflow.com/questions/987973/why-does-eclipse-complain-about-override-on-interface-methods. If you have the language level of the project set to Java 1.8 (which is not showing in the screen shot, but rather only the SDK version), and still get this problem, make sure that your module are configured to use the project-language-level (Ctrl+Shift+Alt+S), and do not override it with something like 1.5. – ethanfar Jun 17 '14 at 10:12
  • I've set the language level to 7.0 for both the project and the two mobile inside the project. I've also changed maven to use java 1.8 jdk, but im still getting the issue. – Nick Jun 17 '14 at 10:32

3 Answers3

3

If it is a maven project, make sure that you have a definition for the maven-compiler-plugin in your pom.xml where you explicitely set the compile and source level to at least 1.6.

For example:

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.2</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
</plugin>

It defaults to 1.5 so @Override is not available yet. Intellij Idea seems to evaluate the compiler plugin even if it's not specified.

1

Override annotation for interfaces is only supported with java 6 and higher.

Check intellij is using the correct jdk and language level, and also maven (or whatever build tool you use outside of intellij). Check you have not overridden the project sdk for this particualr module.

NimChimpsky
  • 46,453
  • 60
  • 198
  • 311
0

Do not write your methods manually. Could you create only a StandardMaterial class that implements a Material interface, and then ctrl + space to generate implemented methods automatically? Also, your getID method does not have an override annotation.

Nathaniel Ford
  • 20,545
  • 20
  • 91
  • 102