Sealed class Item( val name: String) { object Item...
# announcements
m
Sealed class Item( val name: String) { object Item1: Item("Mango") object Item2: Item("Grapes") } How to add Item objects in a list with function? Sample: val items = listOf( Item.Item1, Item.Item2)
g
not sure what you're after, can you clarify the question?
p
Your example literally works as written: https://pl.kotl.in/GIJFcZNeC
m
@Gama11 suppose I have 100 objects. How can I add then in a list?
p
If you add
kotlin-reflect
to the classpath, you can use
Item::class.sealedSubclasses