简体   繁体   English

@Override编译错误,实现接口(Eclipse JRE7 Windows)

[英]@Override compile error, implementing an interface (eclipse jre7 Windows)

I am getting compile errors in eclipse when using the @Override annotation for a class that is implementing an interface. 将@Override批注用于实现接口的类时,在eclipse中出现编译错误。

JDK compliance level is set to 1.7. JDK合规性级别设置为1.7。

I am using the latest version of the jdk7. 我正在使用最新版本的jdk7。

Error: "The method {methodname} of type {classname} must override a superclass method" 错误:“类型为{classname}的方法{methodname}必须覆盖超类方法”

 public interface DataDictionary { public Map<String, ? > getAllEntries(String dictionaryName); ... ... } public class StringDictionary implements DataDictionary { @Override // this generates the error public Map<String, ?> getAllEntries(String dictionaryName) { // some implementation return dataDictEntries; } 

If you are using eclipse then remove the method deceleration in your subclass(StringDictionary ) then compiler will ask you to implement unimplemented method in super class. 如果您使用的是eclipse,则删除子类(StringDictionary)中的方法减速,然后编译器将要求您在超类中实现未实现的方法。 then with the help of eclipse you use option Add unimplemented method . 然后在eclipse的帮助下使用选项Add unimplemented method

Hope so it will solve your problem. 希望它能解决您的问题。

I've tried exactly your code - no problem at all. 我已经完全尝试了您的代码-完全没有问题。 JDK1.6 should be sufficient, as @Override for interfaces was added in JDK1.6. JDK1.6应该是足够的,因为@Override的接口在JDK1.6加入。 From all I can see in the question, your code is correct and should work fine. 从我在问题中看到的所有内容来看,您的代码是正确的,应该可以正常工作。

I suggest things like restart Eclipse or change the method then change it back, it seems something inside Eclipse got out of sync with your code. 我建议诸如重新启动Eclipse或更改方法然后将其更改回之类的事情,看来Eclipse内部与您的代码不同步。

另一个建议是,删除eclipse为您生成的类文件,对文件进行一些编辑(如注释),保存并让eclipse重新为您构建。

I think have solved it. 我认为已经解决了。 Earlier I was only modifying the workspace properties only but using maven project with SVN. 早些时候,我只修改了工作区属性,而是将Maven项目与SVN一起使用。 Maven was internally setting property of each project to use "Project Specific 1.5 java compliance" at each update. Maven在内部将每个项目的属性设置为在每次更新时使用“ Project Specific 1.5 java兼容”。

I changed each project to use workspace JDK compliance and removed project specific settings in SVN projects to prevent from future errors after code update. 我更改了每个项目以使用工作区JDK遵从性,并删除了SVN项目中的项目特定设置,以防止代码更新后出现将来的错误。

Thanks. 谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM