java.lang.IllegalArgumentException: API 接口不得扩展其他接口 Retrofit 2
java.lang.IllegalArgumentException: API interfaces must not extend other interfaces Retrofit 2
我在使用 Retrofit 2 beta 2 时遇到下一个问题:
java.lang.IllegalArgumentException: API interfaces must not extend other interfaces.
这是因为我有一个 Retrofit 的 API 接口,像这样:
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);
}
然后,我还有另外三个接口,其中三个是从这个 RetrofitBaseAPI 接口扩展而来的。
当我尝试使用给定接口调用 retrofit.create(Class class) 时,我总是收到此错误。
据我所读,唯一的解决方案是创建三个独立接口。是真的吗?有人知道另一种解决方案吗?
我觉得我们需要复制代码有点奇怪,但是,也许有一个我不明白的原因......
提前致谢!
谢谢,
编辑:使用最终 Retrofit 2 发行版时出现同样的问题。我想这是 Retrofit 的限制....
不可能有基本的 Retrofit 界面。
JakeWharton - Retrofit 的作者:
Retrofit favors composition over inheritance. One interface per service.
正如您已经发现的那样,唯一的解决方案是创建三个独立的接口。
我在使用 Retrofit 2 beta 2 时遇到下一个问题:
java.lang.IllegalArgumentException: API interfaces must not extend other interfaces.
这是因为我有一个 Retrofit 的 API 接口,像这样:
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);
}
然后,我还有另外三个接口,其中三个是从这个 RetrofitBaseAPI 接口扩展而来的。
当我尝试使用给定接口调用 retrofit.create(Class class) 时,我总是收到此错误。
据我所读,唯一的解决方案是创建三个独立接口。是真的吗?有人知道另一种解决方案吗?
我觉得我们需要复制代码有点奇怪,但是,也许有一个我不明白的原因......
提前致谢!
谢谢,
编辑:使用最终 Retrofit 2 发行版时出现同样的问题。我想这是 Retrofit 的限制....
不可能有基本的 Retrofit 界面。
JakeWharton - Retrofit 的作者:
Retrofit favors composition over inheritance. One interface per service.
正如您已经发现的那样,唯一的解决方案是创建三个独立的接口。