공부

[kotlin] when(type)

승가비 2022. 8. 11. 00:22
728x90
when (x) {
    is Int -> print(x + 1)
    is String -> print(x.length + 1)
    is IntArray -> print(x.sum())
}

https://kotlinlang.org/docs/typecasts.html#smart-casts

 

Type checks and casts | Kotlin

 

kotlinlang.org

 

728x90
저작자표시 비영리 (새창열림)