7
在Java中,我们被告知strictly avoid using enums on Android,因为它们占用了两倍的内存。Android性能Kotlin枚举类
这是否适用于Kotlin的enum class
?将Kotlin enum
编译为Java enum
?
在Java中,我们被告知strictly avoid using enums on Android,因为它们占用了两倍的内存。Android性能Kotlin枚举类
这是否适用于Kotlin的enum class
?将Kotlin enum
编译为Java enum
?
它会出现,是的。
我在科特林创造了这个:
enum class Thingies {
Red,
Green,
Blue
}
而且随着javap -v
反编译它,这里是头:
public final class Thingies extends java.lang.Enum<Thingies>
minor version: 0
major version: 52
flags: ACC_PUBLIC, ACC_FINAL, ACC_SUPER, ACC_ENUM
底线:他们是相同的,所以你可能要善待他们一样的方法。
它们完全一样,Kotlin Enum 是 Java JVM Enum。
您可能也有兴趣是否真的应该避免在Android上枚举:https://stackoverflow.com/questions/29183904/should-i-strictly-avoid-using-enums-on-android和https: //stackoverflow.com/questions/5143256/why-was-avoid-enums-where-you-only-need-ints-removed-from-androids-performanc – Ilya