Created
October 15, 2021 18:53
-
-
Save Sintrastes/dc09b2db881962767a160a3a9d484487 to your computer and use it in GitHub Desktop.
Example of how to emulate multiple recievers with bounded polymorphism in Kotlin
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
interface Logging { | |
fun log(message: String) | |
} | |
interface Prompt { | |
fun promptUser(): String | |
} | |
fun <Ctx> Ctx.exampleFn() where Ctx: Logging, Ctx: Prompt { | |
val message = promptUser() | |
log("Enter a message of length exactly 3:") | |
if (message.length == 3) { | |
log("Good!") | |
} else { | |
log("Not so good.") | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment