In Java we are told to strictly avoid using enums on Android because they take up twice the memory.
这也适用于Kotlin 的enum class
人吗?Kotlin enum
会被编译成Java enum
吗?
In Java we are told to strictly avoid using enums on Android because they take up twice the memory.
这也适用于Kotlin 的enum class
人吗?Kotlin enum
会被编译成Java enum
吗?
It would appear so, yes.
我在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
一句话:它们是一样的,所以你可能必须以同样的方式对待它们.