Java switch : variable declaration and scope

后端 未结 7 666
予麋鹿
予麋鹿 2020-12-11 03:14

How does the Java compiler handle the following switch block ? What is the scope of the \'b\' variable ?

Note that the \'b\' variable is declared only in the first b

7条回答
  •  北海茫月
    2020-12-11 03:45

    Your case blocks do not have any local scope. It's not a series of if...else if...else blocks, java implements it as a series of GOTOs.

提交回复
热议问题