Last active
March 15, 2019 20:20
-
-
Save renaudcerrato/5a88c59297adf525047a2e65a7022a95 to your computer and use it in GitHub Desktop.
Kotlin InterfaceDelegation
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 View { | |
fun click() | |
fun toggle() | |
} | |
class ViewImpl: View { | |
override fun click() { println("click!") } | |
override fun toggle() { println("toggle!") } | |
} | |
class EmptyDelegate(view: View): View by view | |
class OverridingDelegate(view: View): View by view { | |
override fun click() { println("CLICK!") } | |
} | |
fun main() { | |
val v = ViewImpl() | |
EmptyDelegate(v).click() | |
OverridingDelegate(v).click() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment