简体   繁体   English

消费者在Kotlin中找不到

[英]Consumer can't find in Kotlin

I want to convert this Java example to kotlin. 我想将此Java示例转换为kotlin。

But... 但...

{responseBody -> .....} Type mismatch. {responseBody-> .....}类型不匹配。

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. 类型不匹配。

Required: Consumer 必需:消费者

Found: (???) -> Unit 找到:(???)->单位

If you change the declaration of handleHeavyContent to this, it will work I guess: 如果您将handleHeavyContent的声明更改为此,我猜它会起作用:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM