Skip to content

2.5 Use enumerated types

Weverton edited this page Aug 29, 2016 · 12 revisions

Lembretes:

  • Construtor para enum só é permitido private;
  • Um enum herda de java.lang.Enum, sendo assim não pode herdar de outras classes;
  • Um enum pode implementar interfaces;

Na label do switch deve ser utilizado o unqualified name no enum.

public class Teste10 {

	public static void main(String[] args) {
		Switch s = Switch.OFF;
		switch (s) {
		case Switch.OFF: // Deve ser utilizado somente o OFF
			System.out.println("It is off!");
			break;
		}

	}

}

enum Switch {
	ON, OFF
}

Clone this wiki locally