fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main(String[] args) {
  11. List<SomeEnum> list = new ArrayList<>();
  12. for (MenuItem key : MenuItem.values()) {
  13. list.add(key.getSomeEnum());
  14. }
  15. System.out.println(list);
  16. }
  17. }
  18.  
  19. enum SomeEnum {
  20. A, B
  21. }
  22.  
  23. enum MenuItem {
  24.  
  25. ItemA("ItemALabel", 0, SomeEnum.A),
  26. ItemB("ItemBLabel", 1, SomeEnum.B);
  27.  
  28. private final String itemLabel;
  29. private final int positionIndex;
  30. private final SomeEnum someEnum;
  31.  
  32. private MenuItem(String itemLabel, int positionIndex, SomeEnum someEnum) {
  33. this.itemLabel = itemLabel;
  34. this.positionIndex = positionIndex;
  35. this.someEnum = someEnum;
  36. }
  37.  
  38. public String getItemLabel() {
  39. return itemLabel;
  40. }
  41.  
  42. public int getPositionIndex() {
  43. return positionIndex;
  44. }
  45.  
  46. public SomeEnum getSomeEnum() {
  47. return this.someEnum;
  48. }
  49.  
  50. }
Success #stdin #stdout 0.05s 711168KB
stdin
Standard input is empty
stdout
[A, B]