Enum枚举变量的处理
1 少用枚举变量,枚举类型 Enum 的内存消耗是静态常量的2倍。
在Google的官方文档中,有如下说明:
Forexample, enums often require more than twice as much memory as static constants.You should strictly avoid using enums on Android.
(https://developer.android.com/topic/performance/memory.html)
2 少用枚举类型,以减少APK的大小。
在Google的官方文档中,有如下说明:
RemoveEnumerations
A single enum can addabout 1.0 to 1.4 KB of size to your app's classes.dex file. Theseadditions can qui

本文探讨了在APP开发中,如何处理Enum枚举变量以减少内存消耗和APK大小。Google建议尽量少用枚举,因为它们比静态常量消耗更多内存。推荐使用@IntDef注解结合ProGuard来转换枚举为整型,以保持类型安全并减小应用体积。
订阅专栏 解锁全文
480

被折叠的 条评论
为什么被折叠?



