简体   繁体   English

@Override在eclipse中给出了错误?

[英]@Override gives error in eclipse?

When I import project from workspace in eclipse, it gives error at @Override annotation. 当我在eclipse中从工作区导入项目时,它会在@Override注释中出错。 If the project has any method that has an annotation it displays as an error and when I remove it works fine, but when I have a major project that has a lot of annotations, what should I do fix it? 如果项目有任何具有注释的方法,它会显示为错误,当我删除它时工作正常,但是当我有一个包含大量注释的主要项目时,我该怎么办呢?

You're getting the error because you're using Java 1.5 which does not support @Override annotations for implementation overrides. 您收到错误是因为您使用的是Java 1.5,它不支持@Override注释以实现覆盖。 Go into the Eclipse settings and set the language level to 1.6. 进入Eclipse设置并将语言级别设置为1.6。

EDIT - to change the language level go To Project > Properties > Java Compiler and set the language level there. 编辑 - 要更改语言级别,请转到“项目”>“属性”>“Java编译器”,然后在其中设置语言级别。 You may need to click to enable project specific settings. 您可能需要单击以启用项目特定设置。

You probably have set your project language level to something below 1.5, where @Override was introduced. 您可能已将项目语言级别设置为低于1.5的值,其中引入了@Override。 Or, you have it set below 6, and the project code uses @Override for methods implementing interface methods, which was only introduced in Java 6. Change your project language level. 或者,将它设置为低于6,项目代码使用@Override实现接口方法的方法,这仅在Java 6中引入。更改项目语言级别。

@Override is not android specific but a java annotation. @Override不是特定于android的,而是java注释。 If you get errors you might have Java 1.5 selected in you eclipse/project settings. 如果出现错误,可能会在eclipse /项目设置中选择Java 1.5。 Change that to Java 1.6 or above and it should disappear. 将其更改为Java 1.6或更高版本,它应该消失。

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

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