Javadoc: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 14: Line 14:


When implementing an interface method in an implementation class without providing any javadoc for the overridden method, the overridden method automatically inherits the javadoc of the interface method, with some additional clarifying message to the effect that the documentation was inherited:
When implementing an interface method in an implementation class without providing any javadoc for the overridden method, the overridden method automatically inherits the javadoc of the interface method, with some additional clarifying message to the effect that the documentation was inherited:
<syntaxhighlight lang='java'>
public interface A {
    /**
    * This is the interface javadoc.
    */
    public void something();
}
</syntaxhighlight>
<syntaxhighlight lang='java'>
public class AImpl implements A {
    @Override
    public void something() {
        System.out.println("something");
    }
}
</syntaxhighlight>
The resulted javadoc:


[[File:javadocInterfaces1.png]]
[[File:javadocInterfaces1.png]]


If the overridden method provides its own javadoc, it will overwrite the interface javadoc:
If the overridden method provides its own javadoc, it will overwrite the interface javadoc:
<syntaxhighlight lang='java'>
</syntaxhighlight>


[[File:javadocInterfaces2.png]]
[[File:javadocInterfaces2.png]]

Revision as of 17:00, 11 October 2018

Internal

Link to External Content

/**
 * For more details see {@linktourl https://example.com}
 */

Inheriting an Overridden Method Comments

When implementing an interface method in an implementation class without providing any javadoc for the overridden method, the overridden method automatically inherits the javadoc of the interface method, with some additional clarifying message to the effect that the documentation was inherited:

public interface A {
    /**
     * This is the interface javadoc.
     */
    public void something();
}
public class AImpl implements A {
    @Override
    public void something() {

        System.out.println("something");
    }
}

The resulted javadoc:

JavadocInterfaces1.png

If the overridden method provides its own javadoc, it will overwrite the interface javadoc:

JavadocInterfaces2.png

However, if the overridden

An overridden method automatically inherits the javadoc of its


If you define javadocs in the subclass they will replace the inherited javadocs, but you can use {@inheritDoc} to include the respective superclass javadoc comments in the subclass javadocs.