Android: enum vs static final ints?

后端 未结 4 1438
闹比i
闹比i 2021-02-01 15:33

What are the advantages (or disadvantages) of having an enum versus having a set of static final ints in Java Android applications? Are there efficienc

4条回答
  •  野的像风
    2021-02-01 16:10

    Well... according to a bald guy Enums are really bad for memory.

    You should use @IntDef/@StringDef annotations:

    public static final int NAVIGATION_MODE_STANDARD = 0;
    public static final int NAVIGATION_MODE_LIST = 1;
    public static final int NAVIGATION_MODE_TABS = 2; 
    
    @IntDef({NAVIGATION_MODE_STANDARD, NAVIGATION_MODE_LIST, NAVIGATION_MODE_TABS})
    public @interface NavigationMode {}
    

    and then

    @NavigationMode
    public abstract int getNavigationMode();
    
    public abstract void setNavigationMode(@NavigationMode int mode);
    

提交回复
热议问题