Skip to content

Instantly share code, notes, and snippets.

@yenerm
Last active November 9, 2020 21:13
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/dd03ec76520509b41319cca0c4ae2b4e to your computer and use it in GitHub Desktop.
Save yenerm/dd03ec76520509b41319cca0c4ae2b4e to your computer and use it in GitHub Desktop.
<!-- Copyright 2020 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
private class NotNullVar<T : Any>() : ReadWriteProperty<Any?, T> {
private var value: T? = null
public override fun getValue(thisRef: Any?, property: KProperty<*>): T {
return value ?: throw IllegalStateException("Property ${property.name} should be initialized before get.")
}
public override fun setValue(thisRef: Any?, property: KProperty<*>, value: T) {
this.value = value
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment