y
03/01/2023, 8:40 AMInt
, Boolean
and MyClass
. I want to be able to exhaustively check which underlying class it is, and then use the underlying class. so I need to be able to statically enumerate all possible classes.
my current solution looks like
sealed class Wrapper<out T> {
abstract val value: T
class Int(override val value: <http://kotlin.Int|kotlin.Int>) : Wrapper<kotlin.Int>()
class Boolean(override val value: kotlin.Boolean) : Wrapper<kotlin.Boolean>()
class MyClass(override val value: MyClass) : Wrapper<MyClass>()
// ...
}
is there a better way to do this, or a way to reduce the boilerplate? ideally I’d like some way to add another case, and “automatically” generate a variant for this class.Michael de Kaste
03/01/2023, 9:34 AMAdam S
03/01/2023, 9:35 AMfun myFunction(value: Int) { }
fun myFunction(value: Boolean) { }
fun myFunction(value: MyClass) { }
y
03/01/2023, 9:38 AMinterface
, so it had to keep repeating override fun myFunction(...)
for each interface implementation. it meant adding another variant needed a new overload in each implementation, and the changes were not local to one area of the code