August 2017
Intermediate to advanced
440 pages
10h
English
The standard library contains extensions for Map and MutableMap with the String key type that provides the getValue and setValue functions. Thanks to them, map can also be used as a property delegate:
class User(map: Map<String, Any>) { // 1
val name: String by map
val kotlinProgrammer: Boolean by map
}
// Usage
val map: Map<String, Any> = mapOf( // 2
"name" to "Marcin",
"kotlinProgrammer" to true
)
val user = User(map) // 3
println(user.name) // Prints: Marcin
println(user.kotlinProgrammer) // Prints: true
This can be useful ...
Read now
Unlock full access