我知道它when { }可以用作 if-else 分支的替代品。但是,如果条件成立,是否可以执行多个分支?
例子:
val x = 5
val y = 4
when {
x.isOdd() -> print("x is odd") //True, prints "x is odd"
y.isEven() -> print("y is even") //Also True, but doesn't get executed
else -> print("x+y is even.")
}
Run Code Online (Sandbox Code Playgroud)
有什么办法让第二行也执行吗?
kotlin ×1