Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is inheritedDoc not defined on constructors? [closed]

I was wondering if there is any valid reason why javadoc does not support inheritedDoc on constructors. Suppose I have

class A
{
/**
 * Constructor of A
 */
A(){}   

/**
 * Does something
 */
public void method(){}
}

class B extends A
{
/**
 * {@inheritDoc}
 */
B(){ super();}

/**
 * {@inheritDoc}
 */
public void method(){}
}

For the method method, I could inherit the javadoc, but why the same cannot be applied for constructors? The javadoc does not get inherited unless I use the inheritDoc tag, which means I am well aware that I would want to reuse the documentation. What should prevent me from doing so for the constructors?

like image 973
Shiva Kumar Avatar asked Feb 13 '13 08:02

Shiva Kumar


People also ask

Why are constructors not inherited C++?

Constructors are different from other class methods in that they create new objects, whereas other methods are invoked by existing objects. This is one reason constructors aren't inherited.

Why constructor does not follow inheritance?

In simple words, a constructor cannot be inherited, since in subclasses it has a different name (the name of the subclass). Methods, instead, are inherited with "the same name" and can be used.

Can constructor be Inhented?

Constructors are not members, so they are not inherited by subclasses, but the constructor of the superclass can be invoked from the subclass.

Can you use this () and super () both in a constructor justify the reason with example?

If we include “this()” or “super()” inside the constructor, it must be the first statement inside it. “this()” and “super()” cannot be used inside the same constructor, as both cannot be executed at once (both cannot be the first statement). “this” can be passed as an argument in the method and constructor calls.


1 Answers

What should prevent me from doing so for the constructors?

Presumably the fact that constructors aren't inherited. While they often end up having the same parameters (with the same meaning) as the constructors in the superclass, it's not nearly such a clear relationship as it is with methods.

I can see the practical value, but equally I can see why something that isn't actually inherited shouldn't have @inheritDoc available. It would be nice if you could specifically inherit bits of documentation - for example, if you're going to pass a parameter value directly to the superclass constructor, it would be nice to be able to effectively link to that documentation...

like image 155
Jon Skeet Avatar answered Nov 15 '22 20:11

Jon Skeet