10

In Eclipse, if I try to apply a "Generate Delegate Methods" refactoring to a Java class like the following:

class Foo implements Bar {
   Bar bar;
}

Eclipse doesn't generate @Override annotations for the generated methods. Is this a bug or is there a good reason for this?

3 Answers 3

31

This doesn't answer your question of why it doesn't add the @Override annotation when you generate delegate methods, but you can add a save action to do it for you upon saving the file. Go to

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

Eclipse Save Actions

Notice the entries for @Override in the Additional actions section. If those are missing for you, click the Configure... button and select the Missing Code tab and select those options:

enter image description here

If you want to add the annotations to an entire project or package in bulk, select the project or package (or multiples), right-click, and choose Source > Clean up...

In the Clean Up dialog, you can configure a custom profile that includes adding missing annotations.

0
4

No good reason, but not a "bug", per se; just a shortcoming. Probably the refactoring is just older than @Override -- older than annotations in general, of course -- and has never been updated.

2
  • Thanks Ernest, I reported this to Eclipse's Bugzilla. May 23, 2011 at 13:32
  • The Bugzilla report can be found here. May 23, 2011 at 15:15
1

Sometimes settings in Window -> Preferences -> Java -> Editor -> Save Actions cause undesired effects especially on XML files while developing Android applications (been there, experienced that). IMHO better solution is to use +1 or right click on package (or class etc...) and then choose Source -> Clean up to add all of your missing @Override annotations.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.