Last active
November 9, 2020 21:13
-
-
Save yenerm/dd03ec76520509b41319cca0c4ae2b4e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- 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