-
-
Save PatilShreyas/14471ba306c20f2a9a40bb950d27da9c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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