Hello, good afternoon.
I have a problem with using ENUM to replace a number in the case. In order to make my code more intuitive and do not use numbers in switch cases, I intend to use an ENUM in their place. Example:
private static enum EnumFrutas {
MACA(0), ABACATE(1), PERA(2);
public final int codigo;
EnumFrutas(int codigo) {
this.codigo = codigo;
}
public int getCodigo() {
return this.codigo;
}
}
public static LinkedList<LinkedList<Eventos>> Working() {
switch (Eventos.get(0).getFruta()) {
case 0:
tomaAcaoParaMaçã;
break;
case 2:
tomaAcaoParaAbacate;
break;
}
}
Knowing that Eventos.get(0).getFruta()
returns an INT, I want to use the value which MACA matches in ENUM (in this case, 0) within the case:
case MACA:
tomaAcaoParaMaçã;
break;
How can I do this, since typing the word MACA itself does not work?