Ian
04/17/2017, 10:37 PMvar s : String? = null
exec {
s = createS()
}
s!!.doSomething()
the exec block is executed synchronously so s will be assigned to a non-null value, but the type system doesn’t know this hence the !!. createS() can only be called within the exec block.
Obviously the !! is ugly, I’m trying to figure out whether there is a better way to get s “out” of the inner code block. I could modify exec such that it will return whatever is returned by the code block, but what if I need to get multiple variables out of the code block?umar
04/18/2017, 4:16 AMdata class Data(val str: String, val num: Double)
So you can use as normal class:
val data = exec {
Data(str = createS(), num = createD())
}
data.str.doSomething()
data.num.doSomething()
Or destructure it immediately:
val (str, num) = exec {
Data(str = createS(), num = createD())
}
str.doSomething()
num.doSomething()Ian
04/18/2017, 5:23 AMumar
04/18/2017, 5:45 AM