2024-06-21
This commit is contained in:
18
Writerside/topics/Delegation.md
Normal file
18
Writerside/topics/Delegation.md
Normal file
@@ -0,0 +1,18 @@
|
||||
# 위임
|
||||
|
||||
```kotlin
|
||||
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()
|
||||
}
|
||||
```
|
||||
Reference in New Issue
Block a user