Skip to content

Instantly share code, notes, and snippets.

@tomergoldst tomergoldst/Singleton.kt
Last active Nov 27, 2018

Embed
What would you like to do?
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
You can’t perform that action at this time.