Is there a better way to write this? I need a refe...
# announcements
n
Is there a better way to write this? I need a reference to the object I am constructing, to be captured by the closure.
Copy code
class Action(val field1: String, val field2: String, var closure: () -> Unit = {} )  { }

val myAction = Action("value1", "value2")

myAction.closure = {            
    callAnotherFunction(myAction)
}

collection.add(myAction)
Is there a way to avoid defining the temp variable and do it all at once?