消费者在Kotlin中找不到 [英] Consumer can't find in Kotlin

查看:79
本文介绍了消费者在Kotlin中找不到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想转换

I want to convert this Java example to kotlin.

但是...

{responseBody-> .....}类型不匹配.

{responseBody -> .....} Type mismatch.

fun handleAudioMessageEvent(event: MessageEvent<AudioMessageContent>) {
    handleHeavyContent(
        event.replyToken,
        event.message.id
    ) { responseBody ->
        val provider = event.message.contentProvider
        val mp4: DownloadedContent
        if (provider.isExternal) {
            mp4 = DownloadedContent(null, provider.originalContentUrl)
        } else {
            mp4 = saveContent("mp4", responseBody)
        }
        reply(event.replyToken, AudioMessage(mp4.uri, 100))
    }
}
.
.
.
private fun handleHeavyContent(
    replyToken: String, messageId: String,
    messageConsumer: Consumer<MessageContentResponse>
) {
    val response: MessageContentResponse
    try {
        response = lineMessagingClient?.getMessageContent(messageId)
            ?.get()!!
    } catch (e: InterruptedException) {
        reply(replyToken, TextMessage("Cannot get image: " + e.message))
        throw RuntimeException(e)
    } catch (e: ExecutionException) {
        reply(replyToken, TextMessage("Cannot get image: " + e.message))
        throw RuntimeException(e)
    }

    messageConsumer.accept(response)
}

类型不匹配.

Type mismatch.

必填: 消费者

发现: (???)->单位

Found: (???) -> Unit

推荐答案

如果您将handleHeavyContent的声明更改为此,它将起作用:

If you change the declaration of handleHeavyContent to this, it will work I guess:

private fun handleHeavyContent(
    replyToken: String, messageId: String,
    messageConsumer: (MessageContentResponse) -> Unit
)

这篇关于消费者在Kotlin中找不到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆