February 2018
Intermediate to advanced
350 pages
7h 35m
English
So, we learned how to use standard delegates, but Kotlin has to offer more with delegation. The map delegation is among those awesome features that comes with delegation. So, what is it? It is the freedom of passing a map as a single parameter instead of numbers of parameters in a function/class constructor. Let's have a look. The following is a program applying map delegation:
data class Book (val delegate:Map<String,Any?>) { val name:String by delegate val authors:String by delegate val pageCount:Int by delegate val publicationDate:Date by delegate val publisher:String by delegate } fun main(args: Array<String>) { val map1 = mapOf( Pair("name","Reactive Programming in Kotlin"), Pair("authors","Rivu Chakraborty"), Pair("pageCount",400), ...Read now
Unlock full access