Why should type argument be specified when using method reference of a generic class in Kotlin?

Viewed 146

Suppose I have a list of lists:

val wrapperList = listOf(
    listOf(1, 2),
    listOf(3, 4),
    listOf(5, 6)
)

Now this does NOT work in Kotlin:

wrapperList.groupBy(List::first, List::last)

Instead the type argument should be specified explicitly:

wrapperList.groupBy(List<Int>::first, List<Int>::last)

This is ugly.

Why is declaring the type mandatory?
Is it possible for Kotlin to infer it automatically like in its lambda expressions?

0 Answers
Related