What is Kotlin delegation and how it works? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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