0

Sample code: https://github.com/line/line-bot-sdk-java/blob/master/sample-spring-boot-kitchensink/src/main/java/com/example/bot/spring/KitchenSinkController.java

I try convert to Kotlin.

But responseBody is Type mismatch.

    handleHeavyContent(
        event.replyToken,
        event.message.id
        ) {responseBody ->
    }

Required: Consumer

Found: (???) -> Unit

user85421
  • 28,957
  • 10
  • 64
  • 87

2 Answers2

0

Hey I had the same problem so after some searches finally I came up with some ways to define a lambda in a function. In your case I would do something like this

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

Hope this helps you

mmdreza baqalpour
  • 1,106
  • 9
  • 18
0

Example fun with Unit and lamba use:


fun x(
    val a: Int,
    val b: (param: Int) -> Unit
) {
    // any code
    b.invoke(a)
}


x(1) { param ->
   println(param) // -> gives 1
}

Your function, after refactoring, must be missing parameter for lamba

P.Juni
  • 2,365
  • 14
  • 26