Can I get Java 5 to ignore @Override errors? [duplicate]

怎甘沉沦 提交于 2019-11-27 19:28:54

问题


Possible Duplicate:
Why does Eclipse complain about @Override on interface methods?

I have some Java code that was written using Eclipse and the Java 6 SDK, so methods that implement an interface are annotated with @Override - an annotation that is legal in Java 6, but not in Java 5.

I'd like to compile the same code using the Java 5 SDK (javac on Mac OS X 10.5). Everything compiles and runs fine except for the @Override annotations. Is there any way I can get javac to ignore the @Override annotations for this project, or is the only solution to remove them all?


回答1:


Apparently you can upgrade to Java 1.5 u21 and this will fix the problem:

Why is javac failing on @Override annotation




回答2:


Unfortunately, the only way is to actually remove the annotations.

If you do want to have your code compile and run with Java 5, you should develop targeting Java 5. Otherwise, you might accidentally rely on a Java 6 specific SDK methods and such.




回答3:


You can use JDK6 to compile 1.5 code. Use -bootclasspath, -target, and -source. Alternatively, I believe the Eclipse compiler treats @Override the same (this might be wrong!).

1.5 has finished its End of Service Life period, and I suggest letting it rot.




回答4:


@Override is valid in java 5 -> http://java.sun.com/j2se/1.5.0/docs/api/index.html?java/lang/Override.html

I recommend that you check your project's compiler settings in Eclipse, perhaps at Project -> Compiler -> Error/Warnings -> Annotations?




回答5:


Java 6 is available for OS X. Check software update. When you have it, set it to be the default java version, and then compile.



来源:https://stackoverflow.com/questions/2135975/can-i-get-java-5-to-ignore-override-errors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!