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

标签 java kotlin line-api

示例代码: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/

相关文章:

java - 抽象类中的构造函数有什么用?

kotlin - 如何从非暂停回调函数从LiveData构建器发出

java - 消费者在 Kotlin 中找不到

kotlin - 如何使用 Kotlin/Native 应用程序将字符串写入剪贴板(Windows 操作系统)?

php - 如何使用 line bot webhook 请求在线路组中使用 @mention/@tag 标记用户

java - 如何实时远程调试更改

java - 带有 Javassist 3.18.2-GA 的 Powermock 1.6.3 产生 NoSuchMethodError

java - 如何解决java.lang.NoClassDefFoundError : javax/xml/bind/JAXBException

java - Android 应用内更新,我应该在哪里设置更新类型?