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] Typecheck with 'is' keyword
原文:https://www.cnblogs.com/Answer1215/p/13880068.html