Skip to content

Instantly share code, notes, and snippets.

@ch8n
Created November 17, 2018 09:54
Show Gist options
  • Save ch8n/3cf4b16dbff8d0a51df6c9e8f8fb5e70 to your computer and use it in GitHub Desktop.
Save ch8n/3cf4b16dbff8d0a51df6c9e8f8fb5e70 to your computer and use it in GitHub Desktop.
Single instance n kotlin java way
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