class X { fun doStuff(name: String) = println("hello, $name") } class X.Y { operator fun invoke( body : X.() -> Unit ) { doStuff("max"); body(); } } fun main() : X.() -> Unit = { doStuff("peter") Y { doStuff("franz") } } /** output would be: * hello peter * hello max * hello franz */