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?
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
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:
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With