Do you put a super() call a the beginning of your constructors?
Posted
by sleske
on Stack Overflow
See other posts from Stack Overflow
or by sleske
Published on 2010-04-26T11:21:12Z
Indexed on
2010/04/26
11:23 UTC
Read the original article
Hit count: 266
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?
© Stack Overflow or respective owner