Guilherme Delgado
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?

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Guilherme Delgado
Guilherme Delgado

Written by Guilherme Delgado

Software Engineer at BlissApplications 🇵🇹 • github.com/GuilhE • When I’m not coding I’m 🧗🏽or 🏄‍♂️

No responses yet

Write a response