how to convert list of child type to list of parent type in Kotlin

3702 views generics

I imagine there is a pretty way of doing this, but I just cannot see it. Say I have the class class Bull: Dog. If I have Set<Bull> bulls and a function fun doSomeCool(vararg input:Dog), what should I do with bulls so that I can pass it to doSomeCool? For example the following doesn't work doSomeCool(*bulls.toTypedArray())

answered question

1 Answer


Your function should be generic like this:

fun <D: Dog> do(vararg d: D)

posted this

Have an answer?


Please login first before posting an answer.