+ 1

What is Kotlin delegation and how it works?

I'm really confused by Kotlin delegation, can somebody provide me with a more practical example? 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() }

29th Aug 2022, 8:19 PM
Alex
Alex - avatar
2 Answers