2016-01-29 98 views
6

我调查这个科特林例如接收器功能类型:在斯卡拉

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函数类型?

回答

6

在Scala中没有与此相当的东西。你只需要使用一个函数,它将HTML作为参数(可能作为一个隐含的参数,但这并不反映在类型中,在这种情况下不太可能)。