Skip to content

Instantly share code, notes, and snippets.

@yenerm
Last active November 9, 2020 21:14
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 yenerm/99146e9c590beefe636f1523e44de3a5 to your computer and use it in GitHub Desktop.
Save yenerm/99146e9c590beefe636f1523e44de3a5 to your computer and use it in GitHub Desktop.
<!-- Copyright 2020 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
override val value: T
get() {
val _v1 = _value
if (_v1 !== UNINITIALIZED_VALUE) {
@Suppress("UNCHECKED_CAST")
return _v1 as T
}
return synchronized(lock) {
val _v2 = _value
if (_v2 !== UNINITIALIZED_VALUE) {
@Suppress("UNCHECKED_CAST") (_v2 as T)
} else {
val typedValue = initializer!!()
_value = typedValue
initializer = null
typedValue
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment