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 在目前所有版本中都是不可以的。

相关文章:

  • 2021-07-18
  • 2022-12-23
  • 2022-02-23
  • 2022-02-24
  • 2021-06-13
  • 2021-11-27
  • 2021-12-24
  • 2021-06-20
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-13
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案