0

What is the difference between kotlin lateinit and lazy?

Jun 16, 2020 in Kotlin by Veerubhotla

1 answers to this question.

0

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.

 

Jun 16, 2020 answered by Sowjanya

Related Questions

0 1 answers

Kotlin Lambda Example

Explain about kotlin lambda expression with example?

Jun 16, 2020 in Kotlin by Irshad
0 1 answers

Kotlin Abstract Class

What is the abstract class in kotlin?

Jun 16, 2020 in Kotlin by Irshad
0 1 answers

Kotlin Default Arguments

How the default argument in kotlin works?

Jun 16, 2020 in Kotlin by Irshad