Caleb Allen
05/07/2018, 10:25 PMclass 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
ResponseHandler().handle(getResponse())