Java switch cases: with or without braces?

前端 未结 8 1800
猫巷女王i
猫巷女王i 2020-12-23 11:05

Consider the following two snippets, with braces:

switch (var) {
  case FOO: {
    x = x + 1;
    break;
  }

  case BAR: {
    y = y + 1;
    break;
  }
}
<         


        
8条回答
  •  梦毁少年i
    2020-12-23 11:33

    This question is probably going to be closed as "argumentative" (BRACE WAR!) but what the heck. I actually like the braces after the cases. To me it makes the ugly switch syntax look more like the rest of the language constructs. (There is no penalty for using braces in this "case")

提交回复
热议问题