February 2018
Intermediate to advanced
350 pages
7h 35m
English
Some functional languages provide a lazy (non-strict) evaluation mode. Kotlin, by default, uses an eager (strict) evaluation.
Kotlin doesn't provide native support for lazy evaluation as part of the language itself, but as part of Kotlin's Standard Library and a language feature named delegate properties (we'll cover this in detail in future chapters):
fun main(args: Array<String>) { val i by lazy { println("Lazy evaluation") 1 } println("before using i") println(i)}
The output will look something like the following screenshot:

After the by reserved word, the lazy() higher-function receives an (() -> T) initializer lambda function ...
Read now
Unlock full access