[Kotlin] Typecheck with 'is' keyword, 'as' keyword for assert type
Kotlin for is with 39 type as
2023-09-14 08:59:13 时间
val randomNumber = Random().nextInt(3) if (randomNumber is BigDecimal) { result = result.add(BigDecimal(36)) }
If you use type check, then 'result' is auto casting to BigDecimal type.
'as' keyword
val randomNumber = Random().nextInt(3) if (randomNumber is BigDecimal) { result = result.add(BigDecimal(36)) } else { val tempResult: String = result as String result = tempResult.toUpperCase() }
相关文章
- [Kotlin] Try catch & Throw
- [Kotlin] Exercise for Map
- [Kotlin] for loop
- Kotlin 朱涛-20 协程 Flow 数据流
- [Kotlin Spring boot] Enable automatically recompile for Spring boot project with devtool
- [Kotlin] implicit getterr && setter (field keyword)
- [Kotlin] Shorthand syntax for FP
- [Kotlin] Exercise for Map
- [Kotlin] Generics basic
- Android问题笔记 - kotlin-stdlib是什么?
- 想使用 Kotlin DSL for HTML 来这样写前端的代码码?
- 《Kotlin极简教程》第五章 Kotlin面向对象编程(OOP)
- 用 Kotlin 的函数式编程 替代 GOF 设计模式
- Kotlin — 心印(熟悉与锻炼Kotlin语法)
- Kotlin的报错提示:java.lang.NumberFormatException: For input string: ““