Jak*_*ski 4 pattern-matching destructuring kotlin
可能这个问题应该由 Kotlin 的作者提出,但我确信在 SO 上有许多 Kotlin 用户对其架构有深入的了解。
例如,我想要以下代码:
data class Person(val name: String, val age: Int)
when (person) {
("John", _) -> print("It is John") //it won't compile
else -> print("It's not John")
}
Run Code Online (Sandbox Code Playgroud)
由于解构使用的component1, component2, etc.方法,我很好奇为什么不能如上所示使用这种简单的值比较。是when机制修改的问题还是破坏本身的问题?
| 归档时间: |
|
| 查看次数: |
1233 次 |
| 最近记录: |