Files
kotlin-examples/Writerside/topics/Delegation.md
2024-06-21 15:01:25 +09:00

234 B

위임

interface Base {
    fun print()
}

class BaseImpl(val x: Int) : Base {
    override fun print() { print(x) }
}

class Derived(b: Base) : Base by b

fun main(){
    val b = BaseImpl(10)
    Derived(b).print()
}