Java – Constructor Chaining
Java語言最厲害的就是Constructor.
Constructor用得好,寫起程式就像是拿起筆來寫文章得心應手.
Constructor Chaining是很重要的.
Constructor用得好,寫起程式就像是拿起筆來寫文章得心應手.
Constructor Chaining是很重要的.
public class Foo {
private int x;
public Foo() {
this(1);
}
public Foo(int x) {
this.x = x;
}
}
重複的code寫越少,
將來修改時就能改得比較好.
小地方可以看出此人的程式功力.
其實就是導引使用這個物件的人去接受並使用「預設值」
回覆刪除而不用去煩惱這個物件底下的參數設計