This is a question about coding style and recommended practices:
As explained in the answers to the question unnecessary to put super() in constructor?, if you write a constructor for a class that is supposed to use the default (no-arg) constructor from the superclass, you may call super()
at the beginning of your constructor:
public MyClass(int parm){
super(); // leaving this out makes no difference
// do stuff...
}
but you can also omit the call; the compiler will in both cases act as if the super() call were there.
So then, do you put the call into your constructors or not?
On the one hand, one might argue that including the super()
makes things more explicit. OTOH, I always dislike writing redundant code, so personally I tend to leave it out; I do however regularly see it in code from others.
What are your experiences? Did you have problems with one or the other approach? Do you have coding guidelines which prescribe one approach?
BTW: A related question (just for reference):
Is there a reason to explicitly code a default constructor when there are no other constructors?
I don't write the super()
call for the same reason I don't write unnecessary casts:
It adds noise to the code without providing any additional information (neither to the compiler nor to the developer reading my code).
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