Skip to content

Instantly share code, notes, and snippets.

@PatilShreyas

PatilShreyas/1-Old.kt Secret

Created Dec 29, 2020
Embed
What would you like to do?
class Success(val result: Any)
class Failure(val message: String)
fun main() {
val result = getResult()
val something = when (result) {
is Success -> {}
is Failure -> {}
else -> { /* Unnecessary part */ }
}
}
fun getResult() = listOf(Success(""), Failure("Failed")).random()
sealed class Result {
class Success(val result: Any): Result()
class Failure(val message: String): Result()
}
fun main() {
val result = getResult()
val something = when (result) {
is Result.Success -> {}
is Result.Failure -> {}
}
}
fun getResult(): Result = listOf(Result.Success(""), Result.Failure("Failed")).random()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment