我在Kotlin Android上尝试使用。 但这是行不通的,因为需要初始化Resonse。 但是我该如何初始化响应
override fun funk(): Response {
var response : Response
try {
response = proceed()
} catch (e: SomeError) {
....
}
return response
}
答案 0 :(得分:1)
您需要使其可为空:
override fun funk(): Response? {
var response : Response? = null
try {
response = proceed()
} catch (e: SomeError) {
....
}
return response
}
您也可以浓缩此方法:
override fun funk() =
try {
proceed()
} catch (e: SomeError) {
null
}