4 ms·
If I’m understanding correctly, languages like rust avoid that problem by throwing a compile error when a match statement doesn’t cover all possible cases. Of
by dwaltrip 5y ago
If I’m understanding correctly, languages like rust avoid that problem by throwing a compile error when a match statement doesn’t cover all possible cases.
Of course, a catch-all would then somewhat reintroduce the problem.
- aardvark179 5y agoYes. The problem you then have is that adding additional values to the enum then either breaks compatibility or relaxes that guarantee. Since Java tries to run old code for as long as possible the only option for switch statements is to ensure there is a fallback so that you at least know there is a problem.