replace constructor with builder: do not suggest to default chain constructor params

This commit is contained in:
anna
2010-11-25 22:24:23 +03:00
parent 7efe81bbed
commit ba1cd24643
5 changed files with 52 additions and 1 deletions
@@ -0,0 +1,18 @@
public class Builder {
private int i = 2;
private int j;
public Builder setI(int i) {
this.i = i;
return this;
}
public Builder setJ(int j) {
this.j = j;
return this;
}
public Test createTest() {
return new Test(i, j);
}
}
@@ -0,0 +1,11 @@
public class Test {
public Test(int i, int j){}
public Test(int j){
this(2, j);
}
void foo(){}
public static void main(String[] args){
new Builder().setJ(1).createTest().foo();
new Builder().setI(2).setJ(3).createTest().foo();
}
}
@@ -0,0 +1,11 @@
public class Test {
public Test(int i, int j){}
public Test(int j){
this(2, j);
}
void foo(){}
public static void main(String[] args){
new Test(1).foo();
new Test(2, 3).foo();
}
}