Skip to content

Instantly share code, notes, and snippets.

@tomergoldst
Last active August 21, 2021 21:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomergoldst/c80b9ca2016650ec68de0d01365691ae to your computer and use it in GitHub Desktop.
Save tomergoldst/c80b9ca2016650ec68de0d01365691ae to your computer and use it in GitHub Desktop.
Kotlin singleton pattern with class paramters
class Singelton private constructor(context: Context) {
companion object {
@Volatile
private var INSTANCE: Singelton? = null
fun getInstance(context: Context): Singelton =
INSTANCE ?: synchronized(this) {
INSTANCE ?: Singelton(context).also { INSTANCE = it }
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment