Skip to content

Instantly share code, notes, and snippets.

@markmaynard
Last active June 10, 2019 12:02
Show Gist options
  • Save markmaynard/86c9afcea85c6654881b3344ca44a40f to your computer and use it in GitHub Desktop.
Save markmaynard/86c9afcea85c6654881b3344ca44a40f to your computer and use it in GitHub Desktop.
Thread safe setter
companion object {
@Volatile var myThing: SomeThing? = null
@Synchronized set(value: SomeThing?) {
val i = myThing
if (i != null) {
field = i
} else {
field = value
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment