【发布时间】:2016-01-29 11:30:47
【问题描述】:
我正在研究这个 Kotlin 示例:
class HTML {
fun body() { ... }
}
fun html(init: HTML.() -> Unit): HTML {
val html = HTML() // create the receiver object
html.init() // pass the receiver object to the lambda
return html
}
html { // lambda with receiver begins here
body() // calling a method on the receiver object
}
我想知道如何在 scala 中编写此代码? scala函数类型如何声明接收者?
【问题讨论】: