Created
September 9, 2019 07:52
-
-
Save bdsaglam/2693a2f6652be81467de4d3b957cbac2 to your computer and use it in GitHub Desktop.
Kotlin Singleton with initialization parameters
This file contains hidden or 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 Singleton private constructor(application: Application) { | |
| companion object { | |
| @Volatile | |
| private var INSTANCE: Singleton? = null | |
| fun getInstance(application: Application): Singleton = | |
| INSTANCE ?: synchronized(this) { | |
| INSTANCE | |
| ?: Singleton(application).also { INSTANCE = it } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment