티스토리 뷰

공부

[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

'공부' 카테고리의 다른 글

[Java] map -> properties `putAll`  (0) 2022.08.11
[kotlin] if not in (!in)  (0) 2022.08.11
[Java] e.printStackTrace -> String  (0) 2022.08.10
[github] actions permissions  (0) 2022.08.10
[JPA] @Query update immediately  (0) 2022.08.10
댓글