【发布时间】:2016-02-17 19:58:42
【问题描述】:
对不起,如果我的标题如此含糊,但我找不到更好的。
我有一个以这种方式公开服务的 rest Api:/api/{type}/{id} 4 'type' 因此返回了 4 个 Class 类型。
所有这些类都扩展自同一个超类
我的问题是我似乎总是必须明确命名返回的类:
Call<Type1> call = apiInterface.get....
Call<Type2> call = apiInterface.get....
等等……
所以我现在做
SuperClass object = null;
switch(type){
case TYPE1:
Call<Type1> call = apiInterface.getType1(id);
call.enqueue(new Callback....{
.......
object = response.body()
}
break;
case TYPE2:
Call<Type2> call = apiInterface.getType2(id);
call.enqueue(new Callback....{
.......
object = response.body()
}
break;
}
感觉很不对。
你有没有办法做得更好,也许是泛型?
谢谢,
【问题讨论】:
标签: android retrofit retrofit2