Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get rid of all @Override errors in Eclipse?

Is there a way to just comment out all the @Overrides that turn out to be Eclipse errors that prevent your app from building/running?

like image 629
ina Avatar asked Nov 09 '11 02:11

ina


People also ask

Is @override annotation necessary?

@Override @Override annotation informs the compiler that the element is meant to override an element declared in a superclass. Overriding methods will be discussed in Interfaces and Inheritance. While it is not required to use this annotation when overriding a method, it helps to prevent errors.

Is @override important java?

The @Override annotation indicates that the child class method is over-writing its base class method. It extracts a warning from the compiler if the annotated method doesn't actually override anything. It can improve the readability of the source code.


4 Answers

So if i understand you there are already @Override annotations in your source code, but you are getting compile errors on them?

If so you have the wrong jdk installed.

You need at least jdk1.5 to use those annotations on methods derived from classes.

You need at least jdk1.6 to use those annotations on methods derived from interfaces.

like image 61
MeBigFatGuy Avatar answered Oct 08 '22 14:10

MeBigFatGuy


In

Window->Preferences->Java->Compiler->Errors/Warnings

There is a group called "Annotations". Under there, check that the

"Missing '@Override' annotation is set to "Ignore" or "Warning" and not "Error".

Edit: I wanted to add that you can get Eclipse to automatically add @Override annotations on files that you save in the Save Actions.

Window->Preferences->Java->Editor->Save Actions

There is a checkbox for "Additional Actions" and if you open the "Configure" window you can select the "Missing Code" tab and select "Add Missing Annotations" where you can select which annotations to automatically add.

like image 40
brianestey Avatar answered Oct 08 '22 14:10

brianestey


I assume you're compiling against Java 1.5 or earlier, where the compiler treats @Override annotations of interface methods as errors.

Use Eclipse to search and replace (remove) all instances of "@Override". Then add back the non-interface overrides using "Clean Up".

Steps:

  1. Select the projects or folders containing your source files.
  2. Go to "Search > Search..." (Ctrl-H) to bring up the Search dialog.
  3. Go to the "File Search" tab.
  4. Enter "@Override" in "Containing text" and "*.java" in "File name patterns". Click "Replace...", then "OK", to remove all instances of "@Override".
  5. Go to "Window > Preferences > Java > Code Style > Clean Up" and create a new profile.
  6. Edit the profile, and uncheck everything except "Missing Code > Add missing Annotations > @Override". Make sure "Implementations of interface methods" is unchecked.
  7. Select the projects or folders containing your source files.
  8. Select "Source > Clean Up..." (Alt+Shift+s, then u), then "Finish" to add back the non-interface overrides.
like image 20
Peter Tseng Avatar answered Oct 08 '22 13:10

Peter Tseng


I have Java 8 on my system and facing the same issue in eclipse. Problem is because JDK Compliance is 1.5

Here is how I fixed it

Open Eclipse, Preference -> Java -> Compiler -> JDK Compliance

Change it to 1.6

like image 40
minhas23 Avatar answered Oct 08 '22 13:10

minhas23