天天看点

APP开发实战145-Enum枚举变量的处理

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 quickly accumulate for complex systems or shared libraries. Ifpossible, consider using the @IntDef annotation and