Re:This should never happen
by jdmichal on Thursday March 31, 2016 @11:13AM
(#11397747)
Also in Java: Switching or if-else chains on an `enum`. It's still a good practice to include a final `else` or `default` case, but it should really never happen. Actually, inclusion of the `default` case will be enforced by the compiler if it can detect a code path that doesn't return. [0]
[0] http://stackoverflow.com/questions/5013194/why-is-default-re...
[ Parent
| on HN ]
I'd prefer to throw an exception in that else block:
throw new AssertionError("Should never happen");I just put a comment as an example. I typically log-and-throw.
Re:This should never happen
by lancefisher on Thursday March 31, 2016 @12:29PM
(#11398403)
This can happen when some other developer adds to your enum not knowing about the use.