Answers for "Kotlin when greater than"

1

Kotlin when greater than

We can use let to achieve this behaviour.

response.code().let {
    when {
        it == 200 -> handleSuccess()
        it == 401 -> handleUnauthorisedError()
        it >= 500 -> handleInternalServerError()
        else -> handleOtherErrors()
    }
}
Posted by: Guest on November-13-2021

Browse Popular Code Answers by Language