Skip to content

Instantly share code, notes, and snippets.

@sudo5in5k
Created January 16, 2020 08:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sudo5in5k/77c6bc399574caf1ba65278e6de346d9 to your computer and use it in GitHub Desktop.
Save sudo5in5k/77c6bc399574caf1ba65278e6de346d9 to your computer and use it in GitHub Desktop.
Singletonを実装するならこう
class Hoge {
companion object {
@Volatile
private var instance: Hoge? = null
fun getInstance() = instance ?: synchronized(this) {
instance ?: Hoge().also { instance = it }
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment