小编Sol*_*Sol的帖子

Scala中带接收器的函数类型

我正在调查这个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
}
Run Code Online (Sandbox Code Playgroud)

我想知道如何在scala中编写这段代码?如何用接收器声明scala函数类型?

lambda scala kotlin

6
推荐指数
1
解决办法
378
查看次数

标签 统计

kotlin ×1

lambda ×1

scala ×1