Is there a way (or could there be a feature of kot...
# random
c
Is there a way (or could there be a feature of kotlin) to enforce handling of a sealed class using method overloading? For example:
Copy code
class ResponseHandler{
    fun handle(success: Response.Success) {}
    fun handle(error: Response.ErrorB) {}
    fun handle(error: Response.ErrorA) {}
}
fun getResponse(): Response{
    val r = Random()
    return when (r.nextInt(3)) {
        0 -> {
            Response.Success()
        }
        1 -> {
            Response.ErrorA()
        }
        2 -> {
            Response.ErrorB()
        }
        else -> {
            throw IllegalStateException()
        }
    }
}
And then calling
Copy code
ResponseHandler().handle(getResponse())