Skip to content

Instantly share code, notes, and snippets.

@adam-arold
Created September 30, 2018 21:36
Show Gist options
  • Save adam-arold/2bf26217a968a4d9366b44f8d643868a to your computer and use it in GitHub Desktop.
Save adam-arold/2bf26217a968a4d9366b44f8d643868a to your computer and use it in GitHub Desktop.
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