开发者

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

This question already has answers here: Closed 10 years ago.

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?


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.


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

Why is javac failing on @Override annotation


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.


@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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜