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

15,788

Solution 1

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?

Solution 2

I too have facing problem and just resolved. Change "Compiler compliance level" to 1.6 in Project->right click->properties->Java compiler.

Solution 3

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>

Solution 4

In eslipse can use different versions of compilers.

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

Solution 5

So, I kept having this problem, and after running through the above solutions a few times, seeing that my version of Java was set to 1.7 all the way down, not using Maven, and so just quitting and restarting Eclipse a couple times as @jdowdell suggested, after which, it would seem to work until the next time I implemented one of these. I realized that when I was re-starting Eclipse it was prompting me to save my files and I realized that my interfaces had not been saved, so the original method, the one being overrode, didn't exist on disk. And this is why quitting and restarting Eclipse fixes the problem.

tl;dr : Check that all your files are saved.

Share:
15,788
jsoc
Author by

jsoc

@joconnell

Updated on June 05, 2022

Comments

  • jsoc
    jsoc almost 2 years

    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.0.

    I am using the latest version of the 6.0 jdk.

    Error: "The method {methodname} of type {classname} must override a superclass method"

    Same code works fine on mac with comparable configuration.

    public interface ChannelIF {
    ...
        public boolean canSendNarrowcast();
        public boolean canSendBroadcast(); 
    }
    
    public class FacebookChannel implements ChannelIF 
    {
    ...
        @Override
        public boolean canSendNarrowcast() { return true; }
    
        @Override
        public boolean canSendBroadcast() { return true; }
    }
    
  • jsoc
    jsoc about 13 years
    Added code sample. Note: code compiles fine in other configurations. I think it has something to do with version of jdk I'm running within linux, or something about my linux eclipse config that I'm just failing to see.
  • jsoc
    jsoc about 13 years
    I suspect that you're right, but where do I check for this within eclipse? The compiler compliance level within eclipse is already set to 6.0 (1.6)
  • M3rlino
    M3rlino about 13 years
    For Eclipse: right button on project -> Properties... > Java compiler, then configure as you want