下面的代碼不能工作,我不明白理由,爲什麼會這樣?如果我可以找到一種方法來在另一個重寫的構造函數中調用構造函數?java構造函數被稱爲anthor覆蓋在執行
通過,我知道可以有一個解決方案,把普通的init代碼放在一個類的函數中。所以,請原諒我這個棘手的問題。
Public AClass extends BClass {
AClass(Context c) {
super(c);
//below has common init code
//init data and some operations
// other operations
}
AClass(Context c, Attr a) {
super(c, a);
this(c) // error
}
}
也,下面也不能正常工作,
AClass(Context c, Attr a) : this(c) {
super(c, a);
}
高度讚賞你的善意幫助。