Community
Participate
Working Groups
snippet switch ("one") { case "one": System.out.println("Accept"); return true; case "two": System.out.println("Unreachable"); return true; default: System.out.println("Fail"); return false; } the second case statement and the default case are unreachable. The compiler can mark them as unreachable code or show a warning that I am using switch on String constant or both :)
Switching on constants is anyway kind of redundant. So IMHO, we should warn when the switch is done on a constant. Something like "Redundant switch on a constant"