Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 544
dmazzoni Avatar asked Jan 25 '10 21:01

dmazzoni


People also ask

Is it necessary to use @override in Java?

It is not necessary, but it is highly recommended. It keeps you from shooting yourself in the foot. It helps prevent the case when you write a function that you think overrides another one but you misspelled something and you get completely unexpected behavior.

Which overriding is not allowed in Java?

If you make any method static then it becomes a class method and not an object method and hence it is not allowed to be overridden as they are resolved at compilation time and overridden methods are resolved at runtime.

Why do we put @override above the definition of some methods?

The @Override annotation allows other developers (and you, when you forget) to know that this method overrides something in a base class/interface, and it also allows the compiler to yell at you if you're not actually overriding anything in a base class.


1 Answers

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.

like image 194
notnoop Avatar answered Oct 25 '22 02:10

notnoop