23.08.28 12:25 작성
·
212
0
fun checkNumberS(obj :NumberS) {
when(obj) { // <<<<< 오류발생줄
is NumberS.SeOne -> {
println("ONE 입니다")
println(obj.a)
println(obj.b)
}
is NumberS.SeTwo -> {
println("TWO 입니다")
println(obj.a)
println(obj.b)
when(obj.a) {
1 -> println("1 입니다")
2 -> println("2 입니다")
3 -> println("3 입니다")
}
}
is NumberS.SeThr -> {
println("THREE 입니다")
println(obj.a)
println(obj.b)
}
}
}
sealed class NumberS {
class SeOne(val a:Int, val b: Int) : NumberS()
class SeTwo(val a:Int, val b: String) : NumberS()
class SeThr(val a:Int, val b: Double) : NumberS()
class SeFou(val a:Int) : NumberS() {
fun sealedFun () {
}
}
}
fun main() {
val c1 = NumberS.SeOne(1, 3)
checkNumberS(c1) // ONE 입니다 1 3
val c2 = NumberS.SeTwo(3, "sealed class")
checkNumberS(c2) // TWO 입니다 3 sealed class 3 입니다
val c3 = NumberS.SeThr(5, 3.1415)
checkNumberS(c3) // THREE 입니다 5 3.1415
}