How to declare an empty mutable collection(List) of generic type in kotlin?
1 Answer
Have a look at the Kotlin reference regarding Collections: List, Set, Map. The following will create an empty mutable list of your desired type:
val yourCollection = mutableListOf<YourType>()
If you rather meant a mutable Collection<List<YourType>>, then maybe the following will help you:
val mutableCollectionWithList : Collection<List<YourType>> = mutableListOf(mutableListOf())
Alternatively if you do not really need an empty list you can also do:
val yourCollection = mutableListOf(YourType(), ...)
And if you rather want an empty list which is not mutable, use the following instead:
val emptyList = emptyList<YourType>()