枚举三部曲之一

##什么是枚举,特点,使用场景 It is a compile-time error if an enum declaration has the modifier abstract or final.

  • 不能被继承,不能修改,否则会编译错误;
  • 枚举作为内部类时,默认静态的,不用声明为 static;
  • 可以在非静态内部类中声明一个枚举类型的变量,而正常情况下非静态内部类中是不允许有静态变量的

##洪水猛兽? https://developer.android.com/topic/performance/memory.html#Overhead

For example, enums often require more than twice as much memory as static constants. You should strictly avoid using enums on Android.

.

A single reference to an int constant (copy of the int itself) also occupies 4 bytes. – BladeCoder Jul 22 '15 at 10:26

@BladeCoder reference to enum instance occupy 4 bytes, but instance occupy additional space itself, it's much more

.

Although I appreciate the other answers providing pros/cons of enums, this answer should be the accepted answer since it provides the best solution for Android, specifically. Support annotations are the way to go. We, as Android developers should be thinking "unless I have a strong reason to use enums, I will use constants with annotations", rather than the other answers' way of thinking "unless I start to get worried about memory/performance later on, I can use enums". Stop yourself now from having performance problems later on! ##其他相似功能实现方式:静态常量,接口,注解

##Thanks: https://docs.oracle.com/javase/specs/jls/se8/html/jls-8.html#jls-8.9

http://gyht0808.iteye.com/blog/489723#comments

posted @ 2018-01-10 14:56  人情世故  阅读(105)  评论(0编辑  收藏  举报
"不管做什么,只要坚持下去就会看到不一样!在路上,不卑不亢!"