ilya.gorbunov
10/09/2017, 3:32 PM@DslMarker
annotation class NodeDsl
@NodeDsl
open class Node(val name: String) {
open fun lookup() = "lookup in: $name"
}
class Example : Node("container") {
val child1 = createChild("child1")?.apply { // with ?
println("child1 lookup = ${lookup()}")
}
val child2 = createChild("child2").apply { // without ?
println("child2 lookup = ${lookup()}") // 'fun lookup(): String' can't be called in this context by implicit receiver. Use the explicit one if necessary
}
private fun createChild(name: String): Node? { // nullable
return Node(name)
}
}