https://kotlinlang.org logo
Title
a

aarjav

01/28/2019, 12:09 AM
How to go from
Function<T,R>?
to
((T) -> R)?
I used an extension property
val Function<T,R>.lambda: ((T) -> R) get() = this::apply
and use it like
func?.lambda
v

voddan

01/28/2019, 2:50 PM
Function<T,R>?
to
((T) -> R)?
are the same type, you shouldn't need converting one to the other
a

aarjav

01/28/2019, 5:22 PM
Maybe I'm missing something here with generics then. do i need to specify in/out somewhere?
the reverse also gives similar type mismatch message
fun <T,R> bar(func: ((T) -> R)? = null) {
    foo<T,R>(func)
}

fun <T,R> foo(func: java.util.function.Function<T, R>? = null) {
    bar<T,R>(func)
}
k

karelpeeters

01/29/2019, 9:50 AM
What about
bar<T,R>{ func.apply(it) }
?