3 ms·
How is "break" in switch statements a footgun in Java? It is annoying boilerplate to need a "break" after each case, but how can it lead to shooting yourself in
by bobbyi_settv 9y ago
How is "break" in switch statements a footgun in Java? It is annoying boilerplate to need a "break" after each case, but how can it lead to shooting yourself in the foot?
- on_and_off 9y agoBecause I have seen more than once devs forgetting to add a 'break;', resulting in more or less subtle bugs. The kotlin/swift way of declaring this flow does not let you do this mistake.
- m2ger 9y agoI recommend using ErrorProne in Your projects. There are several problems its compiler will catch and fall through begin one of them: http://errorprone.info/bugpattern/FallThrough http://errorprone.info/bugpattern/FallThrough It might take quite a lot of work to fix (or bypass) all the reported problems in a large codebase but it is worth it.
- jfoutz 9y agoby forgetting it in that one long clause.