【发布时间】:2020-04-30 16:04:36
【问题描述】:
我想在 Kotlin 中分配一个变量:
val clickedBlock: Block? = when (event.action) {
...
Action.RIGHT_CLICK_AIR -> {
p.getLineOfSight(null, 5).forEach { block ->
if (block.type != Material.VOID_AIR) {
block // I want to assign the variable with this
}
}
null // and not always with this
}
else -> null
}
但是 IntelliJ 说它总是会返回第二个空值。
如果forEach循环内的if语句为真无需引入另一个变量,我如何实现变量clickedBlock将被分配块(而不是空)?
【问题讨论】:
标签: kotlin