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