Effectively using property delegation function lazy
in kotlin.
Using lazy in kotlin
We all know kotlin’s standard delegation function lazy
which lazily initialises our object, let’s say you have condition if this object is initialised you need to either dispose the resources.
Now normally we would do the following
and when we need to dispose resource we would do
Catch
But there is catch this would internally run the lazy initialisation logic
and then dispose the resource, we are unnecessarily initialising and then disposing.
Instead we can use a public method that lazy interface provides, by this we are effectively using the lazy property delegation.