具有两级通用抽象类的继承

时间:2015-06-18 19:07:38

标签: java generics inheritance android-asynctask polymorphism

该代码如何无法启动汽车的doInBackground实现。我错过了什么吗?我不是在谈论异常或崩溃,它永远不会被执行。

这是我的代码段:

FourWheels.java

public abstract class FourWheels<Params, Progress, Result> extends AsyncTask<Params, Progress, Result> {
    @Override
    protected abstract Result doInBackground(Params... params);
}

Car.java

public class Car extends FourWheels<Void, Void, String> {
    @Override
    protected String doInBackground(Void... params)
    {
        String dummy = "dummy";
        return dummy;    
    }
}

MainActivity.java

Car car = new Car();
FourWheels fourwheels = (FourWheels)car;
fourwheels.execute(); // This should call doInBackground from Car...

0 个答案:

没有答案