cleiter
01/06/2017, 11:32 AMclass Once<T> : ReadWriteProperty<Any, T> {
private var value: T? = null
override fun getValue(thisRef: Any, property: KProperty<*>): T =
value ?: throw IllegalStateException("Property has not been initialized")
override fun setValue(thisRef: Any, property: KProperty<*>, value: T) {
if (this.value != null) throw IllegalStateException("Property has already been initialized")
this.value = value
}
}
usage is var s: String by Once()
and it will behave as you stated