有一个变量:
var itemDecorators: MutableList<ItemDecorator>? = null
在函数的最开始,我正在尝试执行以下操作:
private fun draw(c: Canvas, rv: RecyclerView, vh: ViewHolder) {
val decorators = itemDecorators ?: return
if (decorators.isEmpty()) return
Kotlin是否有可能将最后两行重构为一个语句,即检查是否为null
,检查是否为空,然后分配,否则return
?
答案 0 :(得分:8)
val decorators = itemDecorators?.takeUnless{ it.isEmpty() } ?: return