From time to time I have to add a new value to a enum type in my project.
public enum Day {
SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY,
FILENOTFOUND //this one is new one
}
What I would like is to have a compile time error for every switch I have that is not treating the new value, like this one:
switch (color) {
case MONDAY:
case TUESDAY:
case WEDNESDAY:
case THURSDAY:
System.out.println("Mondays are bad.");
break;
case FRIDAY: System.out.println("Fridays are better.");
break;
case SATURDAY:
case SUNDAY: System.out.println("Weekends are best.");
break;
}
Having a default: that throws some exception is not good enough, I would like it to be compile time.
I don't think this is possible but maybe someone has a neat trick...
I thought Findbugs would have a rule to find those but I only saw this: Eq: Covariant equals() method defined for enum (EQ_DONT_DEFINE_EQUALS_FOR_ENUM)
EDIT: I'm choosing Mark's reply, I do use Eclipse and that sounds just like what I needed! I am not an expert in findbugs at all so I might have missed such functionality, though I don't think so.