In Java we are told to strictly avoid using enums on Android because they take up twice the memory.
Does this apply to enum class
in Kotlin aswell? Will a Kotlin enum
be compiled into a Java enum
?
In Java we are told to strictly avoid using enums on Android because they take up twice the memory.
Does this apply to enum class
in Kotlin aswell? Will a Kotlin enum
be compiled into a Java enum
?
It would appear so, yes.
I created this in Kotlin:
enum class Thingies {
Red,
Green,
Blue
}
And decompiled it with javap -v
, and here is the header:
public final class Thingies extends java.lang.Enum<Thingies>
minor version: 0
major version: 52
flags: ACC_PUBLIC, ACC_FINAL, ACC_SUPER, ACC_ENUM
Bottom line: they are identical, so you probably have to treat them the same way.
They are exactly the same thing, a Kotlin Enum is a Java JVM Enum.
You can most definitely use enums in Android now, they specifically discussed this topic in this Google I/O video: https://www.youtube.com/watch?v=IrMw7MEgADk (if you don't want to watch the whole video, then start from 11:30 ish to 14:40).