Switch能否用string做参数
2017-03-21 16:13
169 查看
在 Java 7之前,switch
只能支持 byte、short、char、int或者其对应的封装类以及 Enum 类型。在 Java 7中,String支持被加上了。
其中ctrType为字符串。
如在jdk 7 之前的版本使用, 会提示如下错误:
Cannot switch on a value of type String for source level below 1.7. Only convertible int values or enum variables are permitted
意为jdk版本太低,不支持。
引申:
在之前的版本,可以利用枚举类型,相关介绍:http://www.cnblogs.com/hyl8218/p/5088287.html
只能支持 byte、short、char、int或者其对应的封装类以及 Enum 类型。在 Java 7中,String支持被加上了。
如在jdk 7 之前的版本使用, 会提示如下错误:
Cannot switch on a value of type String for source level below 1.7. Only convertible int values or enum variables are permitted
意为jdk版本太低,不支持。
引申:
在之前的版本,可以利用枚举类型,相关介绍:http://www.cnblogs.com/hyl8218/p/5088287.html
相关文章推荐
- Switch能否用string做参数?
- Switch能否用String做参数?
- Switch能否用string做参数
- Switch能否用string做参数
- Switch能否使用String做参数
- Switch能否用string做参数?
- Java中 Switch能否用string做参数?
- Switch能否用String做参数
- Switch能否用string做参数
- Switch能否用string做参数
- Switch能否用string做参数?
- Switch能否用string做参数
- Switch能否用string做参数?
- Switch能否用String做参数
- java中switch能否使用String作为参数?
- Switch能否用string做参数?
- Switch能否用string做参数?
- Switch能否用string做参数
- switch能否用String做参数?
- 我用的是jdk1.7,但switch传string的参数报错