I have an Enum file with a few values in Java. In my main program, I have a function that receives an integer as parameter and I have to perform different actions depending on that value, which is the same as the number that the enum elements have.
I'm doing the following:
public String operation(int option, int chosenBox){
String result = "";
switch(option){
case 0:
model.startGame(this.playersName);
result = "...";
break;
case 1:
model.play();
result = "...";
break;
I need to change the cases' options to point to the elements of the enum instead of the numbers, because sometime I'll need to add an element into the enum and I'd eventually need to change all numbers.
The enum is called MenuOption, and I've tried to do this:
case OpcionMenu.PLAY.ordinal(): // This is for case 0
But the following error appears: "constant expression required".