@Override compile error, implementing an interface (eclipse jdk1.6.0_23 linux)

后端 未结 8 969
耶瑟儿~
耶瑟儿~ 2021-01-04 01:38

I am getting compile errors in eclipse when using the @Override annotation for a class that is implementing an interface.

Compiler compliance level is set to Java 6.

相关标签:
8条回答
  • 2021-01-04 01:54

    In eslipse can use different versions of compilers.

    See сonfiguration in eclipse Preference->Java->Compiler "Compiler compliance level". You must choose "1.6".

    0 讨论(0)
  • 2021-01-04 01:54

    Check the Runtime library, the compiler settings are probably different

    Right click on the project name, properties, Java Build Path, Libraries

    Look at the version of JRE System Library, more than likely it's set to 1.5 or lower. Select JRE System library, then click remove Click Add Library, select JRE System Library, Next Then either Workspace Default, or

    0 讨论(0)
  • 2021-01-04 01:56

    I just found that when using maven I needed to also modify the pom.xml to have the compiler plugin. I had all my settings properly specified, but I needed this one:

    <build>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <inherited>true</inherited>
          <configuration>
              <source>1.6</source>
              <target>1.6</target>
          </configuration>
        </plugin>
      </plugins>
    </build>
    
    0 讨论(0)
  • 2021-01-04 01:56

    Sounds like your method signatures don't match. They must be the same, including things such as thrown checked exceptions. Post your code!

    0 讨论(0)
  • 2021-01-04 01:58

    This feature is only valid in Java 6 and higher. I see you are using jdk 1.6. That's good. Possible cause: You are compiling with -source 1.5. Is this the case? If so, can you change it to -source 1.6?

    0 讨论(0)
  • 2021-01-04 02:02

    I had this same problem for about an hour, and then it seemed to mysteriously solve itself. I wish I know what I did. I had started with workspace settings set for 1.6, unwittingly having project settings set to 1.5 compatibility. I discovered this and changed project compiler settings to 1.6, which resolved some errors, but not the @Override issue for interfaces. Some combination of the following fixed it:

    1. Changing the jre back from jdk to the jre that Eclipse custom installed (or somebody, wasn't me).
    2. Disabling project specific settings in the compiler section, and also clicking Reset to Defaults, on both project and workspace settings for compiler.
    3. Quitting Eclipse and rerunning it as Administrator (I copied eclipse into Program Files on Windows from a .zip, not from an installer; and I think it can't change its config files being a child of that folder without being run as administrator - but I could be dead wrong).

    One fellow apparently solved the issue via complete uninstall and reinstall of all java/eclipse related components: http://p2p.wrox.com/book-beginning-android-application-development/87299-override-errors-despite-1-6-a.html

    0 讨论(0)
提交回复
热议问题