Skip to content

Instantly share code, notes, and snippets.

@zawzaww
Last active July 11, 2018 15:33
Show Gist options
  • Save zawzaww/d09a0c5b3f3a6684785a85d0e730adb0 to your computer and use it in GitHub Desktop.
Save zawzaww/d09a0c5b3f3a6684785a85d0e730adb0 to your computer and use it in GitHub Desktop.
Setup sigleton pattern in Kotlin.
class NewsAppModel {
companion object {
private var INSTANCE: NewsAppModel? = null
fun getInstance(): NewsAppModel {
if (INSTANCE == null) {
INSTANCE = NewsAppModel()
}
val i = INSTANCE
return i!!
}
}
private constructor() {
EventBus.getDefault().register(this)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment