Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
25
Task/Delegates/Kotlin/delegates.kotlin
Normal file
25
Task/Delegates/Kotlin/delegates.kotlin
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
// version 1.1.51
|
||||
|
||||
interface Thingable {
|
||||
fun thing(): String?
|
||||
}
|
||||
|
||||
class Delegate(val responds: Boolean) : Thingable {
|
||||
override fun thing() = if (responds) "delegate implementation" else null
|
||||
}
|
||||
|
||||
class Delegator(d: Delegate) : Thingable by d {
|
||||
fun operation() = thing() ?: "default implementation"
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
// delegate doesn't respond to 'thing'
|
||||
val d = Delegate(false)
|
||||
val dd = Delegator(d)
|
||||
println(dd.operation())
|
||||
|
||||
// delegate responds to 'thing'
|
||||
val d2 = Delegate(true)
|
||||
val dd2 = Delegator(d2)
|
||||
println(dd2.operation())
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue