Skip to content

Instantly share code, notes, and snippets.

@kittinunf
Last active April 21, 2016 05:51
Show Gist options
  • Save kittinunf/733673ad1ea85b6088e4d3aa32af2519 to your computer and use it in GitHub Desktop.
Save kittinunf/733673ad1ea85b6088e4d3aa32af2519 to your computer and use it in GitHub Desktop.
interface Fooable {
fun foo(): String
}
class FooImpl : Fooable {
override fun foo() = "I am fooImpl"
}
class AnotherFooImpl : Fooable {
override fun foo() = "I am anotherFooImpl"
}
class X(impl: Fooable) : Fooable by impl
fun main(args: Array<String>) {
val x = X(FooImpl())
println(x.foo()) //print I am fooImpl
val y = X(AnotherFooImpl())
println(y.foo()) //print I am anotherFooImpl
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment