Better Switch-Case for Java!

1 · Lalit Prakash Vatsal · May 25, 2021, 11:30 a.m.
Let’s start with the question, what is wrong with the switch-case anyway? Here’s a simple example of a switch-case in Java: Can you see the problem here? It is the unnecessary “ceremony” of writing the “break” statement on each case! You can argue that we can just return after each case-block, while this is a brilliant idea but, then the ceremony would be of writing “return” in each block 😜 you can even miss that! In fact, the return statement at every case-block means that every block should ...