What does this print?
interface Calc {
fun add(a: Int, b: Int): Int
}
class Base : Calc {
override fun add(
a: Int, b: Int
) = a + b
}
class Wrap(c: Calc) : Calc by c
fun main() {
println(Wrap(Base()).add(2, 5))
}
Try it in the online Kotlin Playground →
[spoiler title="Solution"]
Answer:
7
Explanation:
by keyword delegates interface implementation to another object.
[/spoiler]