https://kotlinlang.org logo
m

Manuel Pérez Alcolea

09/25/2020, 10:55 PM
Is it possible to specify the type of a function reference in the very same expression I'm referencing in? for example, instead of
Copy code
val function: ((Char) -> Unit) = ::println
println(function)
something like
Copy code
println(::println) // but this fails because it's ambiguous
c

Cedrick Cooke

09/25/2020, 11:30 PM
println(::println as (Char) -> Unit)
if I remember correctly.
m

Manuel Pérez Alcolea

09/25/2020, 11:36 PM
I tried that (including the missing parentheses) but it didn't work. It seems the compiler tries to get the reference and then cast it
so the error is the same
4 Views