I'm wondering if someone can clarify my understanding of backing fields. I have this property defined in an `object`:
val wordle = Wordle()
get() {
if (this.lastWordListRefresh + 1.hours < Clock.System.now()) {
return Wordle().also {
<http://this.log.info|this.log.info>("Refreshing Wordle state")
this.lastWordListRefresh = Clock.System.now()
}
}
return field
}
My understanding was that returning a different value from
get
would set the backing field. But it seems that, if
lastWordListRefresh
has "expired", it returns a new object once, and then continues using the old backing object for subsequent calls. Is there a way to make it so that the value returned from
get
sets the backing field? I essentially want a property that expires, and then lazily refreshes itself.