A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

RT, switch 语句后面的控制表达式的数据类型有哪些?

6 个回复

正序浏览
JDK1.7版后String和八种数据类型都可以了
回复 使用道具 举报
byte,short,int,char,String(JDK1.7后),枚举(JDK1.5后)
回复 使用道具 举报
short int  枚举,String
回复 使用道具 举报
byte short int char     JDK1.7以后就可以用枚举还有string 类型了
回复 使用道具 举报
实际上 switch 只支持 int,其他类型都应该算是语法糖。

根据 Oracle 官方文档:
  1. The type of the Expression must be char, byte, short, int, Character, Byte, Short, Integer, String, or an enum type (§8.9), or a compile-time error occurs.
复制代码


char, byte, short, int, Character, Byte, Short, Integer, String,以及 enum。
回复 使用道具 举报
boolean。。。
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马