I am using JRE 1.6 version and aware of JRE 1.5 trouble while using @Override
with interface.
I imported a new project (Spring + Maven ) and Eclipse giving error on every @Override
annotation whenever any interface method is overridden.
Things I tried till now
Edit 1:
I am getting following error
The method XXX of type XXX must override a superclass method.
Edit 2:
Code Sample
Interface declaration
public interface HelperService {
public RequisitionTypeDTO getRequisitionTypeDTO(int id) throws Exception;
}
Implementation:
@Service
public class HelperServiceImpl implements HelperService{
@Override // Getting error for this line
public RequisitionTypeDTO getRequisitionTypeDTO(int id) throws Exception{
// Bla Bla Bla
}
}
EDIT 3:
I am able to build and run my application successfully irrespective of this errors. Just not happy with red error flags all over the source code.
Such an error is easy to make, and difficult to catch, which is a dangerous combination. Using the @Override annotation prevents you from making such errors. You should be in the habit of using @Override whenever you override a superclass method, or implement an interface method.
@Override @Override annotation informs the compiler that the element is meant to override an element declared in a superclass. Overriding methods will be discussed in Interfaces and Inheritance.
If you don't use the annotation, the sub-class method will be treated as a new method in the subclass (rather than the overriding method). 2) It improves the code's readability.
You can make the methods default in the interface itself, Default methods are introduced in interfaces since Java8 and if you have default methods in an interface it is not mandatory to override them in the implementing class.
Check if the RequisitionTypeDTO
in interface is the same type as RequisitionTypeDTO
in implementation (different imports).
If ok then try adding maven-compiler-plugin
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
and Maven
->Update project configuration...
from context menu of your project - because that is the way you should set compilation jre.
And of course try mvn clean
, in Eclipse Project
->Clean...
If everything fails create new simple project with minimal code and check if there is the same error.
I got this too, and I did have a "Java Builder" set. Further investigation showed that the problem was that my "Compiler Compliance Level" was set to 1.5 rather than 1.6.
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