Last active
August 21, 2021 21:11
-
-
Save tomergoldst/c80b9ca2016650ec68de0d01365691ae to your computer and use it in GitHub Desktop.
Kotlin singleton pattern with class paramters
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 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