Any ideas how to make this prototype work: ```fun ...
# getting-started
d
Any ideas how to make this prototype work:
Copy code
fun myMethod(): java.util.function.Function<Int,String> {
   return {  value: Int ->
      if(value == 42) "42" else ""
   } as Function<Int,String>  // heh
}
r
Use a SAM conversion:
Copy code
fun myMethod(): Function<Int, String> {
    return Function { value: Int ->
        if (value == 42) "42" else ""
    }
}
Or shorter:
Copy code
fun myMethod(): Function<Int, String> =
    Function { if (it == 42) "42" else "" }
d
Perfect that compiles nicely, thanks!
👍 1
👍🏿 1