I have a mutable list which can have items of different data classes. For example, val items: List<ItemData>, and ItemData is a class of
sealed class ItemData {
data class itemOne(
val valueOne
) : ItemData()
data class itemTwo(
val valueTwo
) : ItemData()
data class itemThree(
val valueThree
) : ItemData()
}
Say I want to take the list and whenever item is of certain type, update some value there. My question is, how to make sure that item is exactly the type I need? I tried with item as ItemData.itemTwo but I get class cast exception, since in my list are items of other types, too.