Skip to content

Instantly share code, notes, and snippets.

@bdsaglam
Created September 9, 2019 07:52
Show Gist options
  • Select an option

  • Save bdsaglam/2693a2f6652be81467de4d3b957cbac2 to your computer and use it in GitHub Desktop.

Select an option

Save bdsaglam/2693a2f6652be81467de4d3b957cbac2 to your computer and use it in GitHub Desktop.
Kotlin Singleton with initialization parameters
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