【发布时间】:2019-05-04 01:02:16
【问题描述】:
我真的不知道如何命名标题,因此我将尽可能地解释它:
val a = b ?: ({
val temp = c.evaluate()
store(temp)
temp // returns temp to the lambda, which will set `a` to `temp` if `b` is null
})()
1:什么有效,我目前使用什么
这很好用,但我理想中想要做的只是使用代码块而不是将 lambda 传递给函数 (({})) 然后对其进行评估。在我的想象中,它看起来像这样:
val a = b ?: {
val temp = c.evaluate()
store(temp)
temp // returns temp to the lambda, which will set `a` to `temp` if `b` is null
}
2:我想要什么
以上内容不有效。我其实只是在寻找更好的写法1。
【问题讨论】:
标签: kotlin