Enum枚举的替代

【Enum枚举的替代】Enums often require more than twice as much memory as static constants.
枚举类型是一个对象。

public class Enum{ String name; int ordinal; }

占用的空间。包含一个String类型,和一个int类型。
而如果用下面的方式,只会占用一个int 的空间大小。
//Toast.java源码中有这样一段定义 /** @hide */ @IntDef({LENGTH_SHORT, LENGTH_LONG}) @Retention(RetentionPolicy.SOURCE) public @interface Duration {}

    推荐阅读