0

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>){}

2 Answers 2

3

That's what generics are for,

fun <T> doSomething(list: MutableList<T>) {
}
Sign up to request clarification or add additional context in comments.

Comments

0

Use Any

 fun doSomething(list: MutableList<Any>) {
    val value = list[0]
    when (value) {
        is String -> {
        }
        is Int ->{}
        is yourcustomclass->{}
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.