January 2018
Intermediate to advanced
434 pages
14h 1m
English
In the following steps, we will learn how to use the lazy delegate in Kotlin:
val / var <property name>: <Type> by <delegate>
class MainActivity : AppCompatActivity() { private val textView : TextView by lazy { findViewById<TextView>(R.id.textView) as TextView } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) textView.text="ABC" }}
The lazy delegate initializes the object on its first access and stores the value, which is then returned for subsequent accesses.
Read now
Unlock full access