【发布时间】:2019-08-07 07:58:58
【问题描述】:
我尝试转换为 Kotlin。
但是 responseBody 的类型不匹配。
handleHeavyContent(
event.replyToken,
event.message.id
) {responseBody ->
}
必填: 消费者
找到:(???) -> 单位
【问题讨论】:
我尝试转换为 Kotlin。
但是 responseBody 的类型不匹配。
handleHeavyContent(
event.replyToken,
event.message.id
) {responseBody ->
}
必填: 消费者
找到:(???) -> 单位
【问题讨论】:
嘿,我遇到了同样的问题,所以经过一番搜索,我终于想出了一些在函数中定义 lambda 的方法。 在你的情况下,我会做这样的事情
fun handleHeavyContent(
event.replyToken,
event.message.id,
response : (ResponseBody) -> Unit){
//do your code and get the response body and pass it to the variable
// get the body from a function or object and then use it like this
val body : ResponseBody //initialize it here
response(body)
}
希望对你有帮助
【讨论】:
使用 Unit 和 Lamba 的示例乐趣:
fun x(
val a: Int,
val b: (param: Int) -> Unit
) {
// any code
b.invoke(a)
}
x(1) { param ->
println(param) // -> gives 1
}
你的函数,在重构之后,一定是缺少 Lamba 的参数
【讨论】: