Reputation: 1269
I'm having an annoying issue with IntelliJ where it's putting yellow warning lines under my @Override annotations when implementing an interface?
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)
Upvotes: 1
Views: 5223
Reputation: 37
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.
Upvotes: 0
Reputation: 49
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.
Upvotes: 3
Reputation: 47290
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.
Upvotes: 1