D
Duane Evenson
A quick question about constructor style:
Which do you prefer, independently built constructors or nested
constructors?
eg.
// Eclipse automatically generated style
AClass() {
}
AClass(String str) {
this.str = str;
}
AClass(String str, int num) {
this.str = str;
this.num = num;
}
or
// "Elements of Java Style" recommended style
AClass(String str, int num) {
this.string = string;
this.num = num;
}
AClass(String str) {
this(str, DEFAULT_NUM);
}
AClass() {
this("", DEFAULT_NUM);
}
Which do you prefer, independently built constructors or nested
constructors?
eg.
// Eclipse automatically generated style
AClass() {
}
AClass(String str) {
this.str = str;
}
AClass(String str, int num) {
this.str = str;
this.num = num;
}
or
// "Elements of Java Style" recommended style
AClass(String str, int num) {
this.string = string;
this.num = num;
}
AClass(String str) {
this(str, DEFAULT_NUM);
}
AClass() {
this("", DEFAULT_NUM);
}