Search code examples
javaoverridingjavadoc

JavaDoc Override


First to address the possibility of duplicates:

I am not asking what Override is, what it means or the @Override outside of the java doc comment. That is I am not asking

/**Some JavaDoc Comment*/
@override
public void methodA(){}

what this means. Hopefully I emphasized not well enough. I am also not asking when to use @Override or what javadoc is or how to do java doc comments. (Yes I emphasized a lot but I would rather over specify the question than get marked as a duplicate for no reason).

Now to the question:

In the java documentation, the comparator class: https://docs.oracle.com/javase/8/docs/api/java/util/Comparator.html#compare-T-T- has the following equals method description:

Overrides:
equals in class Object
Parameters:
obj - the reference object with which to compare.
Returns:
true only if the specified object is also a comparator and it imposes the same ordering as this comparator.
See Also:
Object.equals(Object), Object.hashCode()

How do I get the Overrides tag in the JavaDoc. When I put @Overrides, it literally types in the description "@Overrides". How do I get that JavaDoc tag like in the Comparator class to show Overrides: equals in class Object?


Solution

  • Based on this tech note (section "Automatic re-use of method comments ", about a third of the way down), the "Overrides" section is automatically generated by the JavaDoc tool if a method overrides another method.

    From the aforementioned link:

    You can avoid re-typing doc comments by being aware of how the Javadoc tool duplicates (inherits) comments for methods that override or implement other methods. This occurs in three cases:

    When a method in a class overrides a method in a superclass When a method in an interface overrides a method in a superinterface When a method in a class implements a method in an interface In the first two cases, if a method m() overrides another method, The Javadoc tool will generate a subheading "Overrides" in the documentation for m(), with a link to the method it is overriding.

    In the third case, if a method m() in a given class implements a method in an interface, the Javadoc tool will generate a subheading "Specified by" in the documentation for m(), with a link to the method it is implementing.

    In all three of these cases, if the method m() contains no doc comments or tags, the Javadoc tool will also copy the text of the method it is overriding or implementing to the generated documentation for m(). So if the documentation of the overridden or implemented method is sufficient, you do not need to add documentation for m(). If you add any documentation comment or tag to m(), the "Overrides" or "Specified by" subheading and link will still appear, but no text will be copied.