Specifically, instead of doing this:
sealed class Event {
data class EventWithName(val name:String):Event()
data class EventWithNumber(val number:Int):Event()
object EventWithoutArgs:Event(){
override fun toString(): String = javaClass.simpleName
}
}
fun main() {
println(Event.EventWithName("hello"))
println(Event.EventWithNumber(123))
println(Event.EventWithoutArgs)
}
I would like to be able to do this:
sealed interface Event {
data class EventWithName(val name:String):Event
data class EventWithNumber(val number:Int):Event
data object EventWithoutArgs:Event
}
fun main() {
println(Event.EventWithName("hello"))
println(Event.EventWithNumber(123))
println(Event.EventWithoutArgs)
}
And still have a string like “EventWithoutArgs” instead of something like “Event$EventWithoutArgs@4edde6e5”
The code just seems simpler and more intuitive right?