Java Enum return Int

前端 未结 8 2013
小鲜肉
小鲜肉 2020-12-13 03:31

I\'m having trouble declaring an enum. What I\'m trying to create is an enum for a \'DownloadType\', where there are 3 download types (AUDIO, VIDEO, AUDIO_AND_VIDEO).

<
相关标签:
8条回答
  • 2020-12-13 04:10

    You can try this code .

    private enum DownloadType {
        AUDIO , VIDEO , AUDIO_AND_VIDEO ;
    
    }
    

    You can use this enumeration as like this : DownloadType.AUDIO.ordinal(). Hope this code snippet will help you .

    0 讨论(0)
  • 2020-12-13 04:14

    In my opinion the most readable version

    public enum PIN_PULL_RESISTANCE {
        PULL_UP {
            @Override
            public int getValue() {
                return 1;
            }
        },
        PULL_DOWN {
            @Override
            public int getValue() {
                return 0;
            }
        };
    
        public abstract int getValue();
    }
    
    0 讨论(0)
提交回复
热议问题