How to extend from AsyncTask as a generic base class?

瘦欲@ 提交于 2019-12-06 04:14:52

问题


There are three different implementations of an AsyncTask:

public class DownloadTask extends AsyncTask<String, Integer, Boolean>
public class JsonParserTask extends AsyncTask<Object, Void, Boolean>
public class PostCommentTask extends AsyncTask<String, Void, HttpRequestResult>

I would like them to extend a BaseAsyncTask which I can use for dependency injection then. The class signatur of AsyncTask looks like this:

public abstract class AsyncTask<Params, Progress, Result>

How can I extend AsyncTask while maintaining the different parameters?

                               | DownloadTask
AsyncTask <-- BaseAsyncTask <--| JsonParserTask
                               | PostCommentTask

回答1:


Try:

abstract class BaseAsyncTask<Params, Progress, Result> 
                  extends AsyncTask<Params, Progress, Result>


来源:https://stackoverflow.com/questions/18900682/how-to-extend-from-asynctask-as-a-generic-base-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!