Created
November 28, 2018 10:07
-
-
Save prasannaboppe/aa3e7fec6c5326a054287d383df388cd to your computer and use it in GitHub Desktop.
Singleton implementation for Kotlin (took it from Google sample)
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
/** | |
* Created by Prasanna on 28-11-2018. | |
*/ | |
class KotlinSingleton { | |
companion object { | |
@Volatile | |
private var INSTANCE: KotlinSingleton? = null | |
fun getInstance(id: String): KotlinSingleton = INSTANCE ?: synchronized(this) { | |
INSTANCE ?: buildInstance(id).also { INSTANCE = it } | |
} | |
private fun buildInstance(id: String) = KotlinSingleton() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment