What is the type of mutablelistof(2, 'j') in kotlin

Viewed 40
Fun main(){
    Val a = mutableListOf(2, 'j')
}
// What is the type of a?

i want to make it like this: val a = mutableListOf , but i dont the type

1 Answers

Common supertypes of Int and Char are Comparable<*> and Serializable, so the type of a is:

  • MutableList<Comparable<*> & Serializable>

Depending on what you will do with the resulting list (e.g. initialize a property, return from a function, etc.), some of the type information will be lost and the type will be "simplified" into:

  • MutableList<out Any>

or:

  • MutableList<Any>
Related