c语言case枚举常量,(2条消息)switch case语句case后的枚举常量不带枚举类型

switch case语句case后的枚举常量不带枚举类型

switch case语句case后的枚举常量不带枚举类型

定义了一个枚举类型

public enum Day

{

SUNDAY, MONDAY, TUESDAY, WEDNESDAY,THURSDAY, FRIDAY, SATURDAY

}

在进行switch case分支时

switch (day)

{

case Day.MONDAY:

.....

break;

报错,an enum switch case label must be the unqualified name of an enumeration constant

提示需要把MONDAY前面的枚举类型去掉

switch (day)

{

case MONDAY:

......

break;

java规定case后面的枚举常量名只能使用unqualified name,switch后已经指定了枚举的类型,case后无需使用全名,而且enum也不存在继承关系

If the type of the switch statement’s Expression is an enum type, then every case constant associated with the switch statement must be an enum constant of that type.

the enum value in the case switch label must be an unqualified name. It inherits the context from the type of the object in the switch() clause, and that cases can simply use unqualified names.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值