【发布时间】:2019-05-05 22:25:04
【问题描述】:
假设我有以下内容:
sealed class Color(val name: String) {
object Red : Color("red")
object Green : Color("green")
object Blue : Color("blue")
object Pink : Color("pink")
object Yellow : Color("yellow")
}
是否可以使用 when 语句检查颜色是否是主要颜色,即:
when(color) {
is Red, Green, Blue -> // primary color work
is Pink -> // pink color work
is Yellow -> // yellow color work
}
【问题讨论】:
-
is Red, is Green, is Blue -> ...
标签: kotlin typechecking kotlin-when