【发布时间】:2019-01-25 10:00:35
【问题描述】:
我想在Retrofit中使用T,但不知道如何在Retrofit.create(X.class)方法中设置T。
public interface SupportService<T> {
@GET
Flowable<BaseResponse<T>> getApi(@Url String url, @Query("data") JsonObject jsonObject);
}
HttpRetrofit.getInstance()
.getRetrofit(this)
.<SupportService<T>>create(SupportService.class)
.getApi("",null)
public class BaseResponse<T>{
public int code;
public String message;
public T data;
}
【问题讨论】:
-
这一行出现错误..
>create(SupportService.class) -
你想做什么?可能只是看看这个。它可能会帮助你。 github.com/sushildlh/Modules/wiki/Retrofit
-
我知道如何使用改造。但我只想在 Api 界面中使用 T 。像公共接口 SupportService
{}。似乎 T 在改造创建(ApiInterface.class)时会出错。就像上面的代码一样。 -
是的,它会给你错误。 Bcoz square 无法预测您的情况。