Sembra essere possibile in Java per scrivere qualcosa del genere:toString Uitvoeringsbesluit enumerazioni Java
private enum TrafficLight {
RED,
GREEN;
public String toString() {
return //what should I return here if I want to return
//"abc" when red and "def" when green?
}
}
Ora, vorrei sapere se è possibile returnin il metodo toString "abc" quando l'enum di il valore è rosso e "def" quando è verde. Inoltre, è possibile fare come in C#, dove si può fare questo ?:
private enum TrafficLight {
RED = 0,
GREEN = 15
...
}
Ho provato questo ma ma sto ricevendo errori di compilazione con esso.
Grazie
Vedi anche http://stackoverflow.com/questions/1419835/understanding-enums-in-java –