gpt4 book ai didi

java - 如何在 Kotlin 中使用 Lambda handleHeavyContent()

转载 作者:行者123 更新时间:2023-12-02 01:57:42 25 4
gpt4 key购买 nike

示例代码:https://github.com/line/line-bot-sdk-java/blob/master/sample-spring-boot-kitchensink/src/main/java/com/example/bot/spring/KitchenSinkController.java

我尝试转换为 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)
}

希望这对你有帮助

关于java - 如何在 Kotlin 中使用 Lambda handleHeavyContent(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57389591/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com