Tsallaka zuwa abun ciki
Justice Tech School

Delegation and lazy

by lazy runs code once on first use. Class delegation reuses an interface implementation.

Example
val heavy by lazy { println("computing"); 42 }
println("before")
println(heavy)
println(heavy)

Exercise

Compute on first use.

val x by  { 1 }

Quiz Test

When does lazy compute?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.