Inside abstract class
, private var instance: AppDatabase?
with @Volatile keyword.
Outside abstract class
, private lateinit var INSTANCE: TitleDatabase
.
Note:
getDatabase()
checks whetherINSTANCE
has been initialized during runtime using property reflection(::INSTANCE.isInitialized
).