'Enum.values()' is recommended to be replaced by 'Enum.entries' since 1.9
Reports calls from Kotlin to values() method in enum classes that can be replaced with entries property read.
Use of Enum.entries may improve performance of your code.
The quick-fix replaces values() with entries.
More details: KT-48872 Provide modern and performant replacement for Enum.values()
Note: entries property type is different from the return type of values() method (EnumEntries<T> which inherits from List<T> instead of Array<T>). Due to this in some cases quick fix inserts extra .toTypedArray() conversion to not break the code, but for most common cases replacement will be done without it (e.g. in for loop).
Example:
enum class Version {
V1, V2
}
Version.values().forEach { /* .. */ }
val firstVersion = Version.values()[0]
functionExpectingArray(Version.values())After the quick-fix is applied:
enum class Version {
V1, V2
}
Version.entries.forEach { /* .. */ }
val firstVersion = Version.entries[0]
functionExpectingArray(Version.entries.toTypedArray())- By ID
Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.
EnumValuesSoftDeprecate
You can suppress this inspection by placing the following comment marker before the code fragment where you no longer want messages from this inspection to appear:
//noinspection EnumValuesSoftDeprecatenote
Actual comment syntax will depend on the code language you are working with
More detailed instructions as well as other ways and options that you have can be found in the product documentation:
Inspection Details | |
|---|---|
By default bundled with: |