9

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

  1. Checked project and workspace specific JRE and compliance level, It is set to 1.6 version.
    enter image description here
  2. Checked JRE library on build path, it is also same.
  3. Changed Java version in project facet to 1.6 (Dont know if it will help)
    enter image description here
  4. Did Maven clean and install (hundred times till now)
  5. Disabled error / warning for Annotations still no luck enter image description here
  6. Eclipse restart (Stupid thing but helps me lots of time)
  7. Last option will be deleting all .setting and .project files if I dont get anything else to try.

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.

E_net4
  • 27,810
  • 13
  • 101
  • 139
Ajinkya
  • 22,324
  • 33
  • 110
  • 161
  • 3
    It's probably nothing, but since you ruled out everything else: Are those really `@override` annotations? It *should* be `@Override` with a capital O. – Joachim Sauer Jun 08 '12 at 11:03
  • @JoachimSauer: Ya its with big `O`. Please tell me how its matter? – Ajinkya Jun 08 '12 at 11:06
  • @Ajinkya: annotation names are class names, so they are case-sensitive like everything else. It *could have* been some entirely unrelated `override` annotation (but even if it were it's unlikely to produce these kinds of errors). So to summarize: it's not relevant, but I saw nothing else that hinted at a problem. – Joachim Sauer Jun 08 '12 at 11:09
  • Sorry, can't help unless you show what is the error you're getting. Also, try creating a new Java Project and create a class that implements `Runnable`. See if you still get the error on the `@Override` for the `run()` method implementation. – adarshr Jun 08 '12 at 11:10
  • @adarshr: I have added error details. Not getting this error with other projects. – Ajinkya Jun 08 '12 at 11:11
  • My only suspicion is the project facet is incorrect. Usually there will be dependency issues. For instance, if you change Java to 6, you can't use Servlet 3.0 and the facet editor would complain. – adarshr Jun 08 '12 at 11:15
  • Could you post a screenshot of the project facet editor also? – adarshr Jun 08 '12 at 11:17
  • Please add an example interface and method to the question. – beerbajay Jun 08 '12 at 11:20
  • @adarshr: I have added screenshot of project facet editor. – Ajinkya Jun 08 '12 at 11:53
  • @beerbajay: Added sample code. – Ajinkya Jun 08 '12 at 11:53
  • Is your Eclipse set to *Build Automatically*? Otherwise, have you tried a full build? Eclipse wouldn't build automatically if you have back-dated your system, for example. There could also be some other *Build Path* errors in your project which may be preventing a full build. You can do a `Window > Show View > Markers` and see if you have any errors that could be preventing a project build. – adarshr Jun 08 '12 at 11:56
  • @adarshr: It is on `build automatically` option. And I am able to build and run my application even with this thousand errors. – Ajinkya Jun 08 '12 at 12:00
  • @Ajinkya Make a small change in your code and try running to see if you see the changes. You could be running stale classes and be under the impression that it is building properly :) – adarshr Jun 08 '12 at 12:01
  • @adarshr: Error gone. Just added Java builder to project. – Ajinkya Jun 08 '12 at 12:07
  • @All: Dont know how builder is related to this and dont know why nothing was selected in builder option. Still thanks a lot for suggestions. – Ajinkya Jun 08 '12 at 12:10

5 Answers5

8

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.

Xeon
  • 5,949
  • 5
  • 31
  • 52
3

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.

Raedwald
  • 46,613
  • 43
  • 151
  • 237
  • That is, this question is effectively similar to http://stackoverflow.com/questions/987973/why-does-eclipse-complain-about-override-on-interface-methods – Raedwald Apr 26 '13 at 11:41
  • Same here. A Maven 'update project' on a project where the POM didn't have a Java version specified triggered the change. – uberdog Jan 07 '15 at 19:08
2

Realized no Builder is selected for current project. Selected Java Builder and boom. No more red flags all over the code.

enter image description here

Ajinkya
  • 22,324
  • 33
  • 110
  • 161
1

I got a similar issue (this was with code that was working perfectly).

A few minutes ago I stopped seeing classes in the same package (Maven java project in eclipse doesn't see classes in same package) and 'fixed' that error by doign a Maven -> update project.

This changed my compiler level to 1.5 and caused a new issue i.e. this topic

(Fixed by explicitly changing my compiler level)

Community
  • 1
  • 1
Toothless Seer
  • 798
  • 9
  • 13
0

I had the same error. For me the problem was "Java" was not selected in properties -> project facet Even though I had my jre and compiler level set correctly I still had the problem.

DS.
  • 604
  • 2
  • 6
  • 24