nhaarman
06/16/2016, 12:41 PMthis
?
I'm trying to create a DSL, with something like the following:
fun test(init: Test.() -> Unit) : Test {
return Test().apply { init() }
}
class Test {
private var v = 0
infix fun add(value: Int) {
v+=value
}
}
fun main(args: Array<String>) {
test {
add 3
add 6
}
}
Unfortunately, it only recognizes the add 3
if I put this
in front of it:
test {
this add 3
}
What is the reason this is necessary?