LastExceed
05/03/2021, 2:45 PMMap
that's guaranteed to be exhaustive, so the return type of get()
isn't nullable? (similar to how when
can skip else
when it's exhaustive)Rob Elliot
05/03/2021, 2:54 PMchristophsturm
05/03/2021, 2:56 PMLastExceed
05/03/2021, 2:56 PMRob Elliot
05/03/2021, 2:57 PMLastExceed
05/03/2021, 2:59 PMwhen
would mean re-computing the values on every lookupDerek Ellis
05/03/2021, 3:02 PMMap
)LastExceed
05/03/2021, 3:04 PMmkrussel
05/03/2021, 3:14 PMgetValue
method that can be used when you know the key will be in the map.LastExceed
05/03/2021, 3:15 PMephemient
05/03/2021, 4:05 PM.withDefault()
has the same issue, the typesystem doesn't know that .get()
can't return null from itclass MyEnumMap(private val delegate: Map<MyEnum, String>) : Map<MyEnum, String> by delegate {
override fun get(key: MyEnum): String = delegate.getValue(key)
}
but there's some issues with delegation + override in earlier Kotlin versions, so do some investigation to check if it works for you. https://blog.jetbrains.com/kotlin/2020/07/kotlin-1-4-m3-generating-default-methods-in-interfaces/#:~:text=fixing%20an%20issue%20with%20delegatesJoost Klitsie
05/04/2021, 9:07 AM