Reputation: 125
is there any way to generate an array of multiple objects?
i want something like this:
doSomething(MutableList<String>) or doSomething(MutableList<Int>)
fun doSomething(list : MutableList<VariableObject>){}
Upvotes: 0
Views: 45
Reputation: 13358
Use Any
fun doSomething(list: MutableList<Any>) {
val value = list[0]
when (value) {
is String -> {
}
is Int ->{}
is yourcustomclass->{}
}
}
Upvotes: 0
Reputation: 29330
That's what generics are for,
fun <T> doSomething(list: MutableList<T>) {
}
Upvotes: 3