Community
Participate
Working Groups
Hi, I've got the folling source code : public class Test { enum Types {One, Two;} public static void main(String[] args) { int val; Types type = Types.One; switch (type) { case One: val = 1; break; case Two: val = 2; break; } System.out.println(val); } } Eclipse complains that the variable val might not be initialized, but the switch/case statement covers all possible values of the enumeration. Is this a bug ?
Nope, this is the intentional behavior. You still need a 'default:' case for future evolutions (i.e. one could add another enum constant in the future, and unless you recompile your code, it may break some assumptions). This behavior is described in the Java language specification. maxime - pls make sure we have some regression test for it.
Added EnumTest#test135.