Last active
July 11, 2018 15:33
-
-
Save zawzaww/d09a0c5b3f3a6684785a85d0e730adb0 to your computer and use it in GitHub Desktop.
Setup sigleton pattern in Kotlin.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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