我还有一个问题要问:
Java Abstract Class (this keyword)
使用以下代码:
public class SuperClass() {
boolean isDoneLoading = false;
ArrayList items;
public SuperClass() {
loadData();
items = new ArrayList();
}
protected void loadData() {
// loadData is a class that requests data from remote server, populates "items"
// and then calls doneLoading when done;
}
protected void doneLoading() {
isDoneLoading = true;
}
}
public class ExtendedClass extends SuperClass {
public ExtendedClass() {
super();
}
protected void doneLoading() {
// how can I get THIS method to be called when the super's doneLoading is called?
}
}
// some other class
new ExtendedClass();
当调用super的doneloading类时,如何获取“child's”(extendedclass)
doneLoading()
类? 最佳答案
如果您想让父程序doneLoading
后跟例程的子程序版本,并且在父程序中保留此功能,则必须以不同的方式命名它们。例如。,
public abstract class SuperClass {
public void doneLoading() {
isDoneLoading();
}
abstract isDoneLoading();
}
另一个选项将调用
super.doneLoading()
的责任委托给子项。