E 'possibile che un enum modifichi il suo valore (dall'interno stesso)? Forse è più facile capire cosa intendo con il codice:Aiuto con le enumerazioni in Java
enum Rate {
VeryBad(1),
Bad(2),
Average(3),
Good(4),
Excellent(5);
private int rate;
private Rate(int rate) {
this.rate = rate;
}
public void increateRating() {
//is it possible to make the enum variable increase?
//this is, if right now this enum has as value Average, after calling this
//method to have it change to Good?
}
}
Questo è vuole che voglio ottenere:
Rate rate = Rate.Average;
System.out.println(rate); //prints Average;
rate.increaseRating();
System.out.println(rate); //prints Good
Grazie
+ 1. Questo è probabilmente il modo migliore per andare. Bel codice succinto anche. – z5h
Ma ... il 'Tasso' non cambierà? – OscarRyz
@Oscar Penso che l'idea è che divorato farebbe qualcosa come 'rate = rate.successor();' – AaronLS