Overriding a method in Eclipse IDE and (non-Javadoc) comment lines

Do you want to change the comment lines generated by Eclipse when you override a method? Here is how to do it.

Almost everything is configurable in Eclipse. If the default values do not work for your project, you should invest time to tune your IDE. Yesterday a colleague told me about a configuration to change something I found annoying every day: By default, when you override a method in a child class in Eclipse you get something like this:





public class ViewDetailsButton extends AbstractExtensibleButton { 



 /* (non-Javadoc)



 * @see org.eclipse.scout.rt.client.ui.form.fields.button.AbstractButton#execClickAction() 









 protected void execClickAction() throws ProcessingException { 



 // TODO Auto-generated method stub 











I never understood why the "(non-Javadoc)" comment lines were generated and I always removed them. This is not really a big deal (moving the cursor, pressing CTRL+D, going back to the method body) and I could live with it. Now that I know that switching off the generation of those line can be configured, I ask myself why I did not did it sooner.

Under preferences, open the "Code Templates" preference page (under the Java code style). Select "Comments > Overriding methods" in the tree and click on the "Edit…" button. In the second Dialog you can edit the pattern.

I have removed the pattern completely. After having saved the changes, it works as expected, when you override the method you don’t have the "(non-Javadoc)" lines anymore.

Even if I do not care about those comment lines, I like to understand the code patterns I meet. If I got it right, the lines were useful when @Override could not be used (@Override was introduced with Java 1.5. Since Java 6 it can also be used for methods defined in a parent interface). My guess is that the "@See" line was used by the developer to keep track of the location of the super method. In addition "(non-Javadoc)" seems to be a marker to define a third sort of comment called "non-Javadoc comment". This is something between multiline comment syntax (/* …*/) and the javadoc comment syntax (/** … */). I could not find out if some tools still understand and handle this syntax or not. To summarize: my guess was correct, this is a legacy pattern and I do not care about it (as far as I remember I never programmed with Java 1.4).

I am always happy to write a blog post about Eclipse configuration. I like to share stuff I have learned and I encourage you to tune your IDE in order to have an Eclipse that does what you need the way you want it. As always we welcome feedback on in the dedicated thread on our Eclipse Forum.

Project Home, Forum, Wiki, Twitter