【发布时间】:2018-06-06 21:01:39
【问题描述】:
我正在尝试将大量 Java 代码转换为 Kotlin。
我在堆栈上找到了如何使用 OkHttp 设置身份验证:
client.authenticator(new Authenticator() {
@Override
public Request authenticate(Route route, Response response) throws IOException {
if (responseCount(response) >= 3) {
return null; // If we've failed 3 times, give up. - in real life, never give up!!
}
String credential = Credentials.basic("name", "password");
return response.request().newBuilder().header("Authorization", credential).build();
}
});
看起来很简单,但AndroidStudio翻译错了,类似于:
client.authenticator(Authenticator { route, response ->
if (responseCount(response) >= 3) {
return@Authenticator null // If we've failed 3 times, give up. - in real life, never give up!!
}
val credential = Credentials.basic("name", "password")
response.request().newBuilder().header("Authorization", credential).build()
})
我收到错误“public open fun Authenticator() 的参数太多”
这里有什么问题?如何解决?在我看来,这在 Kotlin 中应该会有所不同。
【问题讨论】:
标签: java android android-studio kotlin