https://kotlinlang.org logo
Title
s

Sudhir Singh Khanger

01/10/2018, 1:02 PM
Can a MutableList have items of two different (object) type? If not what are my alternatives?
a

Alexander Khyzhun

01/10/2018, 1:03 PM
mutableList<Any>
👍🏽 1
p

pteale

01/10/2018, 1:47 PM
Do they have a common base class, use the base class instead of Any if so
☝️ 1
c

cedric

01/10/2018, 5:15 PM
@Sudhir Singh Khanger Note that there are very few cases where
List<Any>
is the right solution, feel free to share your code if you need some help
s

Sudhir Singh Khanger

01/10/2018, 6:08 PM
Thanks everybody. @cedric I am learning Kotlin by writing a Udacity Android Nanodegree project. I need to pass two simple model classes to a heterogeneous-RecyclerView Adapter. I am passing them as one MutableList. I am not very familiar with the collections class in Kotlin. That's on my list once I finish this sample app. https://github.com/sudhirkhanger/baking-app-kotlin