2017-06-03 62 views
7

在Java中,我们被告知strictly avoid using enums on Android,因为它们占用了两倍的内存。Android性能Kotlin枚举类

这是否适用于Kotlin的enum class?将Kotlin enum编译为Java enum

+2

您可能也有兴趣是否真的应该避免在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

回答

7

它会出现,是的。

我在科特林创造了这个:

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 

底线:他们是相同的,所以你可能要善待他们一样的方法。

4

它们完全一样,Kotlin Enum Java JVM Enum。