Community
Participate
Working Groups
Build ID: I20070921-0919 (3.4M2) Switch on enum requires default case even if all enum entries are covered. I believe this is too strict check. There's already detector for this kind of errors ('Enum type constant not covered on `switch`') which could be used (in the background) in this case to check if all enum constants are covered in switch statement. public class EnumTest { enum MyEnum { A, B } final String test; public EnumTest(MyEnum e) { // error: The blank final field test may not have been initialized switch (e) { case A: test = "a"; break; case B: test = "a"; break; // default: test = "unknown"; // enabling this line fixes above error } } }
We are strictly following the language spec here. The extra warning you refer to is a courtesy of the Eclipse compiler. As far as I remember, the spec argument for adding the default is for binary compatibility reasons. If later on you add a new enum constant, the already compiled code is still safe, and will run through the default case.
Added EnumTest#test146
Verified for 3.4M3 using I20071029-0010