question: is there any case where `values()` is preferable to `enum.entries` after Kotlin 1.9?
diego-gomez-olvera
11/30/2023, 10:28 AM
I do not know if this is the proper channel for this, or this is more for potential future changes
k
Klitos Kyriacou
11/30/2023, 10:50 AM
The only reason I can think of when you might need
values()
is if you need to call a function that takes an array of enums. If
values()
didn't exist, you'd have to use
entries.toTypedArray()
. However, I think such a use case would be extremely rare.
👍 2
e
ephemient
11/30/2023, 10:56 AM
you aren't losing anything in that case anyway: both
values()
and
entries.toTypedArray()
construct a new
Array<Enum>
ephemient
11/30/2023, 10:57 AM
I can imagine that you might not be able to use
entries
if you are a library building with a newer Kotlin while targeting an older Kotlin's API, or expressly want to avoid kotlin-stdlib dependencies for shrinking purposes (e.g. https://jakewharton.com/shrinking-a-kotlin-binary/)