What does this print?
fun build(
block: StringBuilder.() -> Unit
): String {
val sb = StringBuilder()
sb.block()
return sb.toString()
}
fun main() {
val s = build {
append("K")
append("t")
}
println(s)
}
Try it in the online Kotlin Playground →
[spoiler title="Solution"]
Answer:
Kt
Explanation:
Lambdas with receivers run as if they are methods on the receiver.
[/spoiler]