Skip to content

Commit

Permalink
Handle when a nullable value is memoized
Browse files Browse the repository at this point in the history
  • Loading branch information
kylecorry31 committed Mar 16, 2024
1 parent fb2045f commit 523fc80
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/main/kotlin/com/kylecorry/luna/cache/MemoizedValue.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class MemoizedValue<T> {
cachedValue = value()
cachedHash = hash
}
cachedValue!!
// This cast is safe because the value is only set in the above block - it also handles if T is nullable
cachedValue as T
}

fun reset(): Unit = synchronized(lock) {
Expand Down

0 comments on commit 523fc80

Please sign in to comment.