Enumeraciones
El tipo enum es una alternativa sobre el uso tradicional de las constantes public static.
Antes:
public class ConstantesDia{
public static int LUNES=1;
public static int MARTES=2;
public static int MIERCOLES=3;
public static int JUEVES=4;
public static int VIERNES=5;
public static int SABADO=6;
public static int DOMINGO=7;
}
Ahora:
public enum Dia {
LUNES, MARTES, MIERCOLES, JUEVES, VIERNES, SABADO, DOMINGO;
}
Se puede definir también con constructores:
public enum Dia {
LUNES(1), MARTES(2), MIERCOLES(3), JUEVES(4), VIERNES(5), SABADO(6), DOMINGO(7);
private int orden;
private Dia(int orden) {
this.orden = orden;
}
public int getOrden(){
return orden;
}
}