Hello, guys. How can i do such thing: I have proje...
# announcements
i
Hello, guys. How can i do such thing: I have project with Java and Kotlin interop. I want to use closures like this:
(Int) -> Unit
and provide them from Java to Kotlin. However, in Java i need to provide
Function1<Int, Unit>
instead of
Consumer<Int>
or something like this. Due to this limitation i need to return
Unit.INSTANCE
or use custom interfaces instead of closures How can i avoid this problem?
r
Couldn't you do fun bla_java(c: Consumer<Int>) and have that call the regular function that takes a Function1<Int, Unit> ?
i
Yes, i could do this. But isn't it better to use
(Int) -> Unit
but
Consumer<Int>
?
r
Yes, I meant you have bla(b: (Int) -> Unit) and bla(b: Consumer<Int>) = bla(x -> b.consume(x)), i.e. the java-friendly one that accepts a consumer just calls the "real" one that takes (Int) -> Unit.
i
oh, i see
However, it is not very clear approach, IMO