Instantiate enum class

后端 未结 9 1530
南笙
南笙 2020-12-03 05:34

Consider I am having the following enum class,

public enum Sample {
    READ,
    WRITE
}

and in the following class I am trying to test th

9条回答
  •  难免孤独
    2020-12-03 06:08

    Internally, enums will be translated to something like this

    class Sample extends Enum {
        public static final Sample READ = new Sample("READ", 0);
        public static final Sample WRITE = new Sample("WRITE", 1);
    
        private Sample(String s, int i)
        {
            super(s, i);
        }
    
        // More methods, e.g. getter
    }
    

    They should not and cannot be initialized.

提交回复
热议问题