Hacker News new | past | comments | ask | show | jobs | submit login

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?



Because 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.


I 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

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.


by forgetting it in that one long clause.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: