Reputation: 2213
why in the example below, with mapTwo
Kotlin can't infer the type of a
?
fun <U> mapOne(f: (Int) -> U): U = TODO()
fun <U> mapTwo(f: Function<Int, U>): U = TODO()
fun <T> mapper(a: T): List<T> = TODO()
fun main() {
mapOne(::mapper)
mapTwo(::mapper) //won 't compile
}
Upvotes: 1
Views: 227
Reputation: 2502
Type inference is not the cause of a compilation error. mapTwo<List<Int>>(::mapper)
will not compile either because of ::mapper
having the type (T) -> List<T>
(KFunction1<T, List<T>>
), which is not assignable to Function<Int, U>
.
Upvotes: 1