October 2019
Intermediate to advanced
434 pages
11h 54m
English
It's possible to cast a variable of one type to another type. If the types are not compatible, an exception is thrown. To perform a type cast in Kotlin, we use the as keyword. We'll explore how to perform a type cast with the following examples:
interface SettingsProvider { fun getSetting(key: String) : String}object SettingsManager : SettingsProvider { ... fun printSettings() = map.forEach { println(it) }}
fun main(args: Array<String>) { val settingsProvider: SettingsProvider = SettingsManager
Read now
Unlock full access