Kotlin

Smart casts in Kotlin



Smart casts

Smart casting converts variable of one type to another type, but as opposed to safe casting, it is done implicitly (we don’t need to use the as or as? cast operator).
Smart casts work only when the Kotlin compiler is absolutely sure that the variable will not be changed after check.
This makes them perfectly safe for multithreaded applications.
Generally smart casts are available for all immutable references (val) and for local mutable references (var).
We have two kinds of…

Leave a Reply

Your email address will not be published. Required fields are marked *