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
?
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.
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.
Constructors are not members, so they are not inherited by subclasses, but the constructor of the superclass can be invoked from the subclass.
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.
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...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With