kotlin 中的三元条件运算符

Ternary Conditional Operator in kotlin

这个表达式在 Kotlin 中的等价物是什么。

a ? b : c

这是错误。

在 Kotlin 中,if 语句是表达式。所以下面的代码是等价的:

if (a) b else c

希望它对你有用。