Post

KotlinKotlin

v
veerubhotla sowmithri

Posted on 26th April 2024|41 views

0
votes

Kotlin Lateinit

What is the difference between kotlin lateinit and lazy?

Answers
P
Sowjanya Kodiganti

Posted on 26th April 2024

Below you can see the difference between kotlin lateinit and lazy:

  • Lateinit

Usually, properties declared as holding a non-null type need to be initialized within the constructor. Still, frequently that is not suitable. For instance, features can be initialized by dependence injection, preferentially within the setup method like a unit test. While this case, you can't provide a non-null initializer within the constructor, however, you still need to avoid null checks while referencing that property within the class body.

  • Lazy 

lazy() is a function that exerts a lambda and returns an example of lazy which can assist as some substitute for performing a lazy property: the initial call to get() performs the lambda moved to lazy() and retains the result, following calls to get() naturally return the retained result.

 

Write your answer

STILL GOT QUERIES?

Get a Live FREE Demo
  • Explore the trending and niche courses and learning maps
  • Learn about tuition fee, payment plans, and scholarships
  • Get access to webinars and self-paced learning videos