Java面试题 switch能否用于byte、long、String上?

1、switch能否作用于byte、long、String上?

可以作用于byte上,不能作用于long上,switch中可以是字符串类型,String(jdk1.7之后可以作用在String上)。

2、扩展总结:

  • switch可以作用于:char、byte、short、int
  • switch可以作用于:char、byte、short、int 对应的包装类
  • switch不可以作用于:long、double、float、boolean,包括它们的包装类

猜你喜欢

转载自blog.csdn.net/weixin_44296929/article/details/108318043
今日推荐