If you use an unchangable variable, then it is better to initialize with by lazy { ... }
or val
. In this case you can be sure that it will always be initialized when needed and at most 1 time.
If you want a non-null variable, that can change it's value, use lateinit var
. In Android development you can later initialize it in such events like onCreate
, onResume
. Be aware, that if you call REST request and access this variable, it may lead to an exception UninitializedPropertyAccessException: lateinit property yourVariable has not been initialized
, because the request can execute faster than that variable could initialize.