0

I have one interface SysPropHelper

package com.byteslounge.spring.tx.sys;

public interface SysPropHelper {

    void initSysProp();

}

and one class (SysPropHelperImpl) which implements this interface

package com.byteslounge.spring.tx.sys;

public class SysPropHelperImpl implements SysPropHelper {

    public void initSysProp() {

        System.out.println("From initSysProp method");
    }

}

Both are in the same package. From main method I just called the initSysProp() method and I got the desired result and the output is

From initSysProp method

Still now everything is fine.

But when I annotated initSysProp() method of SysPropHelperImpl class with @Override annotation, surprisingly I got the below mentioned error

The method initSysProp() of type SysPropHelperImpl must override a superclass method

Code after annotated initSysProp() method with @Override annoation

package com.byteslounge.spring.tx.sys;

public class SysPropHelperImpl implements SysPropHelper {

    @Override
    public void initSysProp() {

        System.out.println("From initSysProp method");
    }

}

Trust me, I don't know why I am getting this error.I have restarted the Eclispe,restarted my machine, but no luck.

I am using Eclipse Luna and JDK version is 1.7. If any one has any clue to fix this, please guide me.

The java compiler level and JRE are 1.7 in eclipse.

enter image description here

enter image description here

enter image description here

enter image description here

Bacteria
  • 8,406
  • 10
  • 50
  • 67
  • 4
    Are you sure that you are compiling your code for 1.7 version, not for 1.5? http://stackoverflow.com/questions/2335655/why-is-javac-failing-on-override-annotation – user3707125 Jun 25 '15 at 21:32
  • possible duplicate of ['Must Override a Superclass Method' Errors after importing a project into Eclipse](http://stackoverflow.com/questions/1678122/must-override-a-superclass-method-errors-after-importing-a-project-into-eclips) – beresfordt Jun 25 '15 at 21:33
  • @ user3707125 yes. It's jdk1.7.0_40 – Bacteria Jun 25 '15 at 21:34
  • 1
    With Oracle JDK 1.8.0_45, I cannot reproduce this behaviour. – Turing85 Jun 25 '15 at 21:34
  • @ Turing85 even in new workspace if I create the same thing, I am not getting any compilation error. – Bacteria Jun 25 '15 at 21:37
  • You've probably set the language level to 1.6. – JB Nizet Jun 25 '15 at 21:37
  • @ beresfordt I don't think it's a duplicate. – Bacteria Jun 25 '15 at 21:38
  • 1
    Though you are using a 1.7 SDK you must be targeting 1.5 bytecode; change the target to 1.6 or greater – beresfordt Jun 25 '15 at 21:38
  • 1
    *"even in new workspace if I create the same thing, I am not getting any compilation error."* So the error is gone? – Turing85 Jun 25 '15 at 21:39
  • @ beresfordt, I don't have any option to use other than 1.7. I am working in client machine and I don't have access to install anything. – Bacteria Jun 25 '15 at 21:45
  • @ Turing85 in my workspace where I am working in project, it is still present. – Bacteria Jun 25 '15 at 21:46
  • 1
    I have not suggested you install anything. 'Though you are using a 1.7 SDK you must be targeting 1.5 bytecode; change the target to 1.6 or greater' – beresfordt Jun 25 '15 at 21:48
  • 1
    Just for documentation: I set my compilation level down to 1.7, 1.6 and 1.5. I was able to reproduce the behaviour on 1.5. So it is very likely that your compilation level (or compile target) is Java 1.5. – Turing85 Jun 25 '15 at 22:02
  • @ Turing85 but in my eclipse java compiler level and JRE all are set in 1.7.I have updated the question with all the settings.Even I can not reproduce the error in different workspace. Any other settings I need to check for this workspace? – Bacteria Jun 25 '15 at 22:06
  • 1
    You are using maven to build? Maybe (one of) the `pom.xml`(s) specifies 1.5 as target? Oh and by the way: please do not write a blank between the @ and people's names. We will not see your message in the inbox if you do that. – Turing85 Jun 25 '15 at 22:08
  • Yes I use maven, but in pom i did not mentioned any thing related to maven-compiler-plugin. – Bacteria Jun 25 '15 at 22:11
  • Probably Eclipse got messed up, restart it and rebuild (clean and rebuild). – m0skit0 Jun 25 '15 at 22:12
  • 1
    @GoodBadandUgly First: if you use maven, your compiler settings in Eclipse do not matter at all. maven executes some compilation command independently from your Eclipse settings. Second: if you build your project, there should be some console output showing the actual compiler command (and I am pretty sure 1.5 is set as source). Please provide this. Third: go in your `pom.xml`, define 1.7 as your source. This should definitively fix the problem. – Turing85 Jun 25 '15 at 22:18
  • All the screen shots look OK, yet something in your workspace is telling Eclipse to compile for 1.5. A full zip file containing a minimal project for reproduction would be ideal for further analysis. – Stephan Herrmann Jun 26 '15 at 21:40

0 Answers0