The problem is that I can not specify a specific value for an element in the enumeration.
enum SimpleEnum { Var1 = 1; // не работает }
Is it possible in Java?
The problem is that I can not specify a specific value for an element in the enumeration.
enum SimpleEnum { Var1 = 1; // не работает }
Is it possible in Java?
Take a look at this example. If you just need to number in order, then Java will do it for you.
enum SimpleEnum { SMTH1, SMTH2 } ... //Имя SimpleEnum.SMTH1.name(); //Порядковый номер SimpleEnum.SMTH2.ordinal(); //Весь сет SimpleEnum.values()... //обычный массив ...
Nearly,
enum SimpleEnum { private int a; Var1(1); private SimpleEnum (int a){ this.a= a; } public int getA(){ return a; } }
Then simply in the Class select SimpleEnum.Var1.getA ();
Source: https://ru.stackoverflow.com/questions/11859/
All Articles