I am really not sure how to name the title, hence I am going to explain it as best as I can:
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: what I would like to have
上面的代码可以做not个工作.我实际上只是在寻找一种更好的方式来编写1.