-1
public enum enumUpdateAction {
NEW(0), CHANGE(1), DELETE(2), DELETE_THRU(3), DELETE_FROM(4);
public int codigo;
enumUpdateAction(int codigo) {
this.codigo = codigo;
}
public int getCodigo() {
return this.codigo;
}
}
...
switch (Eventos.get(0).getUpdateaction()) {
case enumUpdateAction.NEW.getCodigo():
ArrayEventos.add(InserirOrdenado(ArrayEventos, Ordem), Ordem);
break;
}
After creating Enum, I am trying to use this value inside a switch (in this case, NEW corresponds to 0 and therefore I am trying to use 0 inside the case), but I get the error "Constant Expression required". Can anyone tell me why it happened?
No, no. Events.get(0). getUpdateaction() returns a number from 0 to 4. Therefore, to not put 0, 1, 2, 3 and 4 in the cases, I created an Enum, because the number 0, for example, refers to NEW. So I don’t have to keep remembering what each number refers to. Understand? ENUM makes this part easier but I’m not getting the int that NEW refers to, which is 0. getUpdateAction() has nothing to do with Enum.
– Marcos Vinicius