我在使用 Retrofit 2 beta 2 时遇到了下一个问题:
java.lang.IllegalArgumentException: API interfaces must not extend other interfaces.
这是因为我有一个 Retrofit 的 API 接口(interface),如下所示:
public interface RetrofitBaseAPI {
@POST
Call<LoginResp> login(@Url String url, @Body LoginReq loginReq);
@POST
Call<String> logout(@Url String url, @Header("Cookie") String sid);
}
例如,其中之一就是这个:
public interface RetrofitWiserLinkAPI extends RetrofitBaseAPI {
@GET("/rs/DeviceIdentification")
Call<DeviceId> getDeviceIdentification(@Header("Cookie") String sid);
}
然后,我还有另外三个接口(interface),它们三个都是从这个 RetrofitBaseAPI 接口(interface)扩展而来的。
当我尝试使用给定接口(interface)调用 retrofit.create(Class class) 时,我总是收到此错误。
据我阅读,唯一的解决方案是创建三个独立的接口(interface)。这是真的吗?有人知道另一种解决方案吗?
我觉得我们需要复制代码有点奇怪,但是,也许有一个我不明白的原因.....
提前致谢!
谢谢,
编辑:使用最终的 Retrofit 2 发行版时同样的问题。我想这是 Retrofit 的限制....
最佳答案
不可能有一个基本的 Retrofit 接口(interface)。
JakeWharton - Retrofit 的作者:
Retrofit favors composition over inheritance. One interface per service.
所以正如您已经发现的那样,唯一的解决方案是创建三个独立的接口(interface)。
关于android - java.lang.IllegalArgumentException : API interfaces must not extend other interfaces Retrofit 2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34181208/