问题
I want to convert this Java example to kotlin.
But...
{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.
Required: Consumer
Found: (???) -> Unit
回答1:
If you change the declaration of handleHeavyContent
to this, it will work I guess:
private fun handleHeavyContent(
replyToken: String, messageId: String,
messageConsumer: (MessageContentResponse) -> Unit
)
来源:https://stackoverflow.com/questions/57398575/consumer-cant-find-in-kotlin