Created
November 17, 2018 09:54
-
-
Save ch8n/3cf4b16dbff8d0a51df6c9e8f8fb5e70 to your computer and use it in GitHub Desktop.
Single instance n kotlin java way
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 Single private constructor(){ | |
companion object{ | |
@Volatile private var instance: Single? = null | |
fun getInstance() = instance?: synchronized(lock=this){ | |
instance?: Single().also{ | |
instance = it | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment