All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jvmMain.ResettableDelegate.kt Maven / Gradle / Ivy

There is a newer version: 0.4.5-alpha6
Show newest version
package org.openrndr.utils
import java.util.concurrent.atomic.AtomicReference
import kotlin.reflect.KProperty

// via https://stackoverflow.com/a/53921217/130168
actual class ResettableDelegate actual constructor(private val initializer: () -> T) {
    private val lazyRef: AtomicReference> = AtomicReference(
            lazy(
                    initializer
            )
    )

    actual operator fun getValue(thisRef: Any?, property: KProperty<*>): T {
        return lazyRef.get().getValue(thisRef, property)
    }

    actual fun reset() {
        lazyRef.set(lazy(initializer))
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy