Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Documentation Override Method does not InheritDoc

A method that overrides another method does not inherit documentation of the method it is overriding. Is there any way to explicitly tell it to inherit the documentation?

/**
  * {@inheritDoc}
  * 
  * This implementation uses a dynamic programming approach.
  */
@Override
public int[] a(int b) {
    return null;
}
like image 780
Verhogen Avatar asked Jul 04 '09 03:07

Verhogen


People also ask

Do overridden methods need javadocs?

Yes. If you don't have javadoc comments on a subclass, javadocs will be be generated based on the superclasses javadoc.

What's {@ Inheritdoc?

The @inheritdoc tag indicates that a symbol should inherit its documentation from its parent class. Any other tags that you include in the JSDoc comment will be ignored. This tag is provided for compatibility with Closure Compiler.

Should I use Inheritdoc?

You should only use @inheritDoc if you intend to add to the original superclass documentation. If you merely want it to be duplicated, Javadoc will do that already, noting that the superclass documentation applies to the subclass's overridden method because the subclass provided no additional documentation.

How do you inherit javadocs?

use {@inheritdoc} explicitly states that comments should be inherited. javadoc documentation : "insert the {@inheritdoc} inline tag in a method main description or @return , @param , or @throws tag comment. the corresponding inherited main description or tag comment is copied into that spot."


1 Answers

According to the javadoc documentation:

Inheriting of comments occurs in all three possible cases of inheritance from classes and interfaces:

  • 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

Comments can be explicitly inherited using the {@inheritDoc} tag. If no comments are provided for an overriding method, comments will be implicitly inherited. Aspects of the inheriting comments (e.g. params, return value, etc.) can be overridden if you so desire.

Importantly, you need to make sure that the source file containing the code with the comment to be inherited is available to the javadoc tool. You can do this by using the -sourcepath option.

like image 154
Brandon E Taylor Avatar answered Sep 21 '22 18:09

Brandon E Taylor