消费者在Kotlin中找不到

时间:2019-08-07 16:16:30

标签: java kotlin line-api

我想将this Java example转换为kotlin。

但是...

  

{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)
}
  

类型不匹配。

     

必填:   消费者

     

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

1 个答案:

答案 0 :(得分:0)

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

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