10

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?

Community
  • 1
  • 1
dmazzoni
  • 12,866
  • 4
  • 38
  • 34

5 Answers5

6

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.

notnoop
  • 58,763
  • 21
  • 123
  • 144
4

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

Why is javac failing on @Override annotation

Community
  • 1
  • 1
skiphoppy
  • 97,646
  • 72
  • 174
  • 218
  • I read that question and all it's answers, and it's not confirmed for JDK 1.5u21 and 1.5u22, see http://stackoverflow.com/questions/2335655/why-is-javac-failing-on-override-annotation#comment3379487_2335752 – Amedee Van Gasse Oct 18 '16 at 11:41
2

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.

Tom Hawtin - tackline
  • 145,806
  • 30
  • 211
  • 305
-1

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

Yoni
  • 10,171
  • 9
  • 55
  • 72
  • +1 - I was going to say the same thing. I use @Override too and I'm still on jdk 1.5. – PSpeed Jan 25 '10 at 22:10
  • 8
    @Override's semantics changed bwetween Java 5 and 6 - in 5, it caused a compiler error when used on a method implementing an interface. In 6, it causes a warning when *not* used on such a method. The question is about how to deal with this difference. – Michael Borgwardt Jan 25 '10 at 22:16
  • Yes @Override is valid in Java 5. But the specification has changed for Java6. In Java6, you can know annotate methods that implement methods of an interface. This was not possible in Java6. – Mihir Mathuria Jan 25 '10 at 22:17
  • "Indicates that a method declaration is intended to override a method declaration in a superclass" -- method-method override is supported, but method-interface override is not! (Or someone please correct me) – Tim Jan 25 '10 at 22:17
  • 1
    It is as I wrote: method-interface override is supported since Java 6, but unfortunately this change is not documented anywhere (I believe there's an official bug concerning the API doc not being updated). – Michael Borgwardt Jan 25 '10 at 22:23
  • One of a number of bugs on this issue: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5008260 – Ash Jan 25 '10 at 23:36
-1

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.

Thorbjørn Ravn Andersen
  • 73,784
  • 33
  • 194
  • 347