ASMR/src/main/kotlin/net/shadowfacts/cacao/util/properties/ResettableLazyProperty.kt

24 lines
436 B
Kotlin
Raw Normal View History

2019-06-26 01:52:17 +00:00
package net.shadowfacts.cacao.util.properties
import kotlin.reflect.KProperty
/**
* @author shadowfacts
*/
class ResettableLazyProperty<Value>(val initializer: () -> Value) {
var value: Value? = null
2019-06-26 02:06:29 +00:00
val isInitialized: Boolean
get() = value != null
operator fun getValue(thisRef: Any, property: KProperty<*>): Value {
if (value == null) {
value = initializer()
}
return value!!
}
fun reset() {
value = null
}
}