1 min readMar 4, 2020
Hello Florina Muntenescu and thanks for this post.
In this situation:
sealed class Result<out T : Any> {
data class Success<out T : Any>(val data: T) : Result<T>()
sealed class Error(val exception: Exception) : Result<Nothing>() {
class RecoverableError(exception: Exception) : Error(exception)
class NonRecoverableError(exception: Exception) : Error(exception)
…
class OtherErrors(exception: Exception) : Error(exception)
}
object InProgress : Result<Nothing>()
}
Latter when using when I wont be able to do something like:
when (result: Result<Int>) {
...
is Result.RecoverableError,
is Result.NonRecoverableError -> {
// it will fail with "Unresolved reference: exception"
result.exception
}
is Result.OtherErrors -> {
...
}
}
How can we solve this?