https://kotlinlang.org logo
Title
i

Ivan

01/01/2019, 5:02 AM
In Java I can have unbound wildcard like
List<List<T> slideBy(Function<T, ?> classifier) {...
How do I do this in Kotlin. I tried
fun <T> slideBy(list: List<T>, function: (T) -> *): List<List<T>> = TODO()
but apparently that’s not legal. Should I do
fun <T> slideBy(list: List<T>, function: (T) -> Any?): List<List<T>> = TODO()
r

robstoll

01/01/2019, 10:54 AM
I would probably be tempted to go with Unit. Because it seems to me it reflects more your use case (don't do anything with the return value). Yet, since this way you can only pass functions with return type Unit I would use
Any?
in the end
👍 1