class CustomApplication: Application() {
companion object {
private var INSTANCE: CustomApplication? = null
@JvmStatic
fun get(): CustomApplication = INSTANCE!!
}
override fun onCreate() {
super.onCreate()
INSTANCE = this
}
}
Or
Copy code
class CustomApplication : Application() {
companion object {
lateinit var instance: CustomApplication
private set
}
override fun onCreate() {
super.onCreate()
instance = this
}
}
Not sure if this is more appropriate for #android. Which one would you prefer for creating an Android Application class? And why?
2️⃣ 4
🤯 1
e
edwardwongtl
09/26/2018, 4:32 AM
Prefer 2️⃣ to avoid Nullable types in Kotlin world.