Why is default required for a switch on an enum?

后端 未结 8 2058
礼貌的吻别
礼貌的吻别 2020-11-29 08:46

Normally, default is not necessary in a switch statement. However, in the following situation the code successfully compiles only when I uncomment the default statement. Can

8条回答
  •  攒了一身酷
    2020-11-29 09:26

    Because compiler cannot guess that there are only two values in the enum and forces you to return value from the method. (However I dont know why it cannot guess, maybe it has something with reflection).

提交回复
热议问题