Say I have a data class that accepts an item, that item could be one of say 4 different things. I know I can use the Any type but what's the best way to narrow the scope to those 4 items?
👍 1
s
Sam
03/18/2022, 3:06 PM
Until we have union types, your best bet might be to replace your data class with a sealed class/interface that has four distinct subtypes
👍 3
😢 2
k
Kamila
03/18/2022, 3:17 PM
I vote for sealed interface the 4 types would implement
➕ 4
s
Stephan Schroeder
03/21/2022, 8:25 AM
a nice advantage of sealed interfaces over sealed classes is that data classes can implement them.