我有一个简单的继承问题..但我无法解决它。
这是基本课程:
public abstract class RpcOkCallback extends RpcTupleCallback
{
// [...] constructor [...]
public boolean callback(int responseCode, final String module, boolean flag){
if (flag){
return onResponse(responseCode, module);
} else {
return onError(responseCode, module);
}
return false;
}
protected abstract boolean onResponse(int responseCode, String module);
protected boolean onError(int responseCode, String module){
return true;
}
}
这是一个重新定义基类的匿名类:
new RpcOkCallback("color_seek_ir", "set_flash_ir"){
@Override
protected boolean onResponse(int responseCode, String module) {
if (seekBar != null) seekBar.setEnabled(true);
return true;
}
@Override
protected boolean onError(int responseCode, String module) {
if (seekBar != null) seekBar.setEnabled(true);
return true;
}
}
问题是..为什么在调用onResponse方法时它正确调用重写方法,而在调用onError方法时,它调用基本情况(“返回true”方法)?我试图将抽象的“返回错误”方法声明为它并且它有效...但我不想在每个匿名类中声明一个类似的基本方法。
有什么想法吗?谢谢:))
答案 0 :(得分:0)
我发现了问题。它实际上正常工作(重写部分),但回调已由另一个" onError"处理。方法(没有被覆盖),因为"返回true"该事件在到达最终目的地之前被取消:(
添加摘要并定义所有方法完成了这项工作,所以感谢海盗船(如果你想添加你的答案或我将标记为解决你的问题:))。