it works, but I want to get compile-time error if I add new value to foo enum and don't add it to initialization. How can I do it in the right way?
Use a final switch statement.
No, seriously, that's the only built-in facility that comes to my mind which checks for the presence of all enum members. Otherwise, you have to put an assert in manually – which, in my opinion, is not exactly a problem either.
David
