如何让这个子类方法覆盖超类方法?
/** Base class */
abstract public class TableGui<T extends DbTable<R>, R extends DbRow> {
protected void launchAddDialog(AddDialog<R> dialog) {
dialog.show();
}
static abstract class TableGuiDialog<R extends DbRow> {
}
static public class AddDialog<R extends DbRow> extends TableGuiDialog<R> {
}
}
/** subclass */
public class EqTableGui extends TableGui<EqTable, Eq> {
protected void launchAddDialog(AddDialog<R> dialog) {
// Do other things
}
}
在子类中,我要么说:
@Override
protected void launchAddDialog(AddDialog<R> dialog) {
dialog.show();
}
我得到“EqTableGui类型的方法launchAddDialog(TableGui.AddDialog)必须覆盖或实现超类型方法”...
或者我删除@Override
,并获取“名称冲突:EqTableGui类型的方法launchAddDialog(TableGui.AddDialog)与TableGui类型的launchAddDialog(TableGui.AddDialog)具有相同的删除,但不会覆盖它”
答案 0 :(得分:1)
应该是:
@Override
protected void launchAddDialog(AddDialog<Eq> dialog) {
dialog.show();
}
R type参数分配给Eq。