Skip to content

Instantly share code, notes, and snippets.

@renaudcerrato
Last active March 15, 2019 20:20
Show Gist options
  • Save renaudcerrato/5a88c59297adf525047a2e65a7022a95 to your computer and use it in GitHub Desktop.
Save renaudcerrato/5a88c59297adf525047a2e65a7022a95 to your computer and use it in GitHub Desktop.
Kotlin InterfaceDelegation
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