I am getting compile errors in eclipse when using the @Override annotation for a class that is implementing an interface.
在为实现接口的类使用@Override注释时,我在eclipse中遇到编译错误。
Compiler compliance level is set to Java 6.0.
编译器合规性级别设置为Java 6.0。
I am using the latest version of the 6.0 jdk.
我使用的是最新版本的6.0 jdk。
Error: "The method {methodname} of type {classname} must override a superclass method"
错误:“类型{classname}的方法{methodname}必须覆盖超类方法”
Same code works fine on mac with comparable configuration.
相同的配置可以在mac上正常工作。
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; }
}
8 个解决方案
#1
14
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
?
此功能仅在Java 6及更高版本中有效。我看到你正在使用jdk 1.6。那很好。可能的原因:您正在使用-source 1.5进行编译。是这样的吗?如果是这样,你可以将它改为-source 1.6吗?
#2
4
I too have facing problem and just resolved. Change "Compiler compliance level" to 1.6 in Project->right click->properties->Java compiler.
我也面临着问题并且刚刚解决了。在Project-> right click-> properties-> Java compiler中将“Compiler compliance level”更改为1.6。
#3
3
In eslipse can use different versions of compilers.
在eslipse中可以使用不同版本的编译器。
See сonfiguration in eclipse Preference->Java->Compiler "Compiler compliance level". You must choose "1.6".
请参阅eclipse首选项中的сonfiguration-> Java-> Compiler“编译器合规性级别”。你必须选择“1.6”。
#4
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:
我刚刚发现在使用maven时我还需要修改pom.xml以获得编译器插件。我已正确指定了所有设置,但我需要这个:
<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>
#5
1
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.
所以,我一直遇到这个问题,经过上述解决方案几次,看到我的Java版本一直设置为1.7,而不是使用Maven,所以只需要退出并重启Eclipse几次@ jdowdell建议,之后,它似乎工作,直到我下次实施其中之一。我意识到,当我重新启动Eclipse时,它提示我保存我的文件,并且我意识到我的界面还没有被保存,因此原始方法,即被覆盖的方法,在磁盘上不存在。这就是为什么退出并重新启动Eclipse可以解决问题的原因。
tl;dr : Check that all your files are saved.
tl; dr:检查所有文件是否都已保存。
#6
0
Sounds like your method signatures don't match. They must be the same, including things such as thrown checked exceptions. Post your code!
听起来你的方法签名不匹配。它们必须相同,包括抛出已检查的异常等内容。发布你的代码!
#7
0
Check the Runtime library, the compiler settings are probably different
检查Runtime库,编译器设置可能不同
Right click on the project name, properties, Java Build Path, Libraries
右键单击项目名称,属性,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
查看JRE系统库的版本,很可能将其设置为1.5或更低。选择JRE System库,然后单击删除单击Add Library,选择JRE System Library,Next然后选择Workspace Default,或
#8
0
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.6,无意中将项目设置设置为1.5兼容性。我发现了这一点并将项目编译器设置更改为1.6,这解决了一些错误,但没有解决接口的@Override问题。下面的一些组合修复了它:
- Changing the jre back from jdk to the jre that Eclipse custom installed (or somebody, wasn't me).
- 将jre从jdk更改为Eclipse自定义安装的jre(或某人,不是我)。
- Disabling project specific settings in the compiler section, and also clicking Reset to Defaults, on both project and workspace settings for compiler.
- 在编译器部分中禁用项目特定设置,并在编译器的项目和工作空间设置上单击“重置为默认值”。
- 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).
- 退出Eclipse并以管理员身份重新运行(我从.zip中将eclipse复制到Windows上的Program Files,而不是从安装程序复制;我认为它不能在不以管理员身份运行的情况下将其配置文件更改为该文件夹的子项 - 但是我可能是错的)。
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
一位研究员通过完全卸载并重新安装所有与java / eclipse相关的组件显然解决了这个问题:http://p2p.wrox.com/book-beginning-android-application-development/87299-override-errors-despite-1-6 -a.html
#1
14
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
?
此功能仅在Java 6及更高版本中有效。我看到你正在使用jdk 1.6。那很好。可能的原因:您正在使用-source 1.5进行编译。是这样的吗?如果是这样,你可以将它改为-source 1.6吗?
#2
4
I too have facing problem and just resolved. Change "Compiler compliance level" to 1.6 in Project->right click->properties->Java compiler.
我也面临着问题并且刚刚解决了。在Project-> right click-> properties-> Java compiler中将“Compiler compliance level”更改为1.6。
#3
3
In eslipse can use different versions of compilers.
在eslipse中可以使用不同版本的编译器。
See сonfiguration in eclipse Preference->Java->Compiler "Compiler compliance level". You must choose "1.6".
请参阅eclipse首选项中的сonfiguration-> Java-> Compiler“编译器合规性级别”。你必须选择“1.6”。
#4
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:
我刚刚发现在使用maven时我还需要修改pom.xml以获得编译器插件。我已正确指定了所有设置,但我需要这个:
<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>
#5
1
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.
所以,我一直遇到这个问题,经过上述解决方案几次,看到我的Java版本一直设置为1.7,而不是使用Maven,所以只需要退出并重启Eclipse几次@ jdowdell建议,之后,它似乎工作,直到我下次实施其中之一。我意识到,当我重新启动Eclipse时,它提示我保存我的文件,并且我意识到我的界面还没有被保存,因此原始方法,即被覆盖的方法,在磁盘上不存在。这就是为什么退出并重新启动Eclipse可以解决问题的原因。
tl;dr : Check that all your files are saved.
tl; dr:检查所有文件是否都已保存。
#6
0
Sounds like your method signatures don't match. They must be the same, including things such as thrown checked exceptions. Post your code!
听起来你的方法签名不匹配。它们必须相同,包括抛出已检查的异常等内容。发布你的代码!
#7
0
Check the Runtime library, the compiler settings are probably different
检查Runtime库,编译器设置可能不同
Right click on the project name, properties, Java Build Path, Libraries
右键单击项目名称,属性,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
查看JRE系统库的版本,很可能将其设置为1.5或更低。选择JRE System库,然后单击删除单击Add Library,选择JRE System Library,Next然后选择Workspace Default,或
#8
0
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.6,无意中将项目设置设置为1.5兼容性。我发现了这一点并将项目编译器设置更改为1.6,这解决了一些错误,但没有解决接口的@Override问题。下面的一些组合修复了它:
- Changing the jre back from jdk to the jre that Eclipse custom installed (or somebody, wasn't me).
- 将jre从jdk更改为Eclipse自定义安装的jre(或某人,不是我)。
- Disabling project specific settings in the compiler section, and also clicking Reset to Defaults, on both project and workspace settings for compiler.
- 在编译器部分中禁用项目特定设置,并在编译器的项目和工作空间设置上单击“重置为默认值”。
- 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).
- 退出Eclipse并以管理员身份重新运行(我从.zip中将eclipse复制到Windows上的Program Files,而不是从安装程序复制;我认为它不能在不以管理员身份运行的情况下将其配置文件更改为该文件夹的子项 - 但是我可能是错的)。
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
一位研究员通过完全卸载并重新安装所有与java / eclipse相关的组件显然解决了这个问题:http://p2p.wrox.com/book-beginning-android-application-development/87299-override-errors-despite-1-6 -a.html