What is the difference between lateinit and lazy in Kotlin?

Following are the key differences between lateinit and lazy in Kotlin :

* In Kotlin, lazy can only be used for val properties while lateinit can only be applied to var because it can't be compiled to a final field. Thus no immutability can be guaranteed.

* You have to use lateinit, if you want your property to be initialized from outside in a way probably unknown beforehand.

Lateinit vs. lazy in Kotlin :
Lateinit Lazy
The lateinit can be initialized from anywhere the object is seen. The lazy can only be initialized from the initializer lambda.
In lateinit, multiple initializations are possible. The lazy can be initialized a single time only.
The lateinit is non-thread safe. It is up to the user to initialize it correctly in a multi-threaded environment. The lazy support thread-safety by default and ensures that the initializer is invoked once.
It is not eligible for nonnull properties. It is also not eligible for nonnull properties.
You can use it only for var. You can use it only for val.
It adds an isInitialized method to check whether the value has been initialized before. In this, the property is never able to un-initialize.
It is not allowed on properties of primitive types. It is allowed on properties of primitive types.