Enum performance

Widely using enums, is there any performance hits when you make them complex?
Like, I have maps of enum classes and my enum can contain:

enum class Foo(@StringRes val nameId: Int, @DrawableRes val image: Int, bar: Int)
val buz = mutableMapOf<Foo, Int>()

Should they be as small as possible or it doesn’t matter? It should matter at least as a static object.

No, it shouldn’t affect the performance. Enums are like compile-time constants and at least in JVM they are compared by their identity (pretty much their memory address), not contents.

2 Likes

On JVM are available EnumMap and EnumSet.

2 Likes