11 switch 是否能作用在 byte 上,是否能作用在 long 上, 是否能作用在 String 上

Java5以前,switch(expr),expr只能是byte,short,int,char;

Java5开始,expr也可以是enum类型,又因为引入了上述基本类型的包装类,因此也可以作用在Byte,Short,Integer,Character上;

Java7开始,expr还可以是字符串String;

因此,switch可以作用在byte,short,int,char,Byte,Short,Integer,Character,enum,String上。

但是,长整型 long 在目前所有版本中都是不可以的。

posted @ 2020-12-18 13:46  卫盾  阅读(200)  评论(0编辑  收藏  举报