Switch能否用string做参数?
由于小编自己的编译环境jdk用的是比较高,在命令窗口输入java -version即可看到。(打开命令窗口win+R,输入cmd,回车)
java version "1.8.0_111"
Java(TM) SE Runtime Environment (build 1.8.0_111-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.111-b14, mixed mode)
String类型一直可以当做Switch的参数,编译和运行都没有出错。一次在资深程序大神的博客看到的,在jdk1.7之前,Switch的参数类型在 Java 7之前,switch 只能支持 byte、short、char、int或者其对应的封装类以及 Enum 类型。在 Java 7中,String支持被加上了。
试了一下,如在jdk 1.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版本太低,不支持。
如有什么不对或者疑问,欢迎提意见!!!
Switch能否用string做参数?的更多相关文章
- Switch能否使用String做参数
在Java语言中Swith可以使用参数类型有:Only convertible int values, strings or enum variables are permitted 可以自动转换为整 ...
- Switch能否用string做参数
在Java5以前,switch(expr)中,exper只能是byte,short,char,int类型(或其包装类)的常量表达式. 从Java5开始,java中引入了枚举类型,即enum类型. 从J ...
- Java的switch是否支持String作为参数,还支持哪些类型?
在Java5以前,switch(expr)中,exper只能是byte,short,char,int类型. 从Java5开始,java中引入了枚举类型,即enum类型. 从Java7开始,exper还 ...
- Switch能否用String类型做参数?
switch(expr): 其中,expr参数可以是一个枚举常量(由整型或字符类型实现)或一个整数表达式,其中整数表达式可以是基本类型int或其包装类Integer.由于byte.short和char ...
- Java基础-继承 利用接口做参数,写个计算器,能完成+-*/运算
38.利用接口做参数,写个计算器,能完成+-*/运算 (1)定义一个接口Compute含有一个方法int computer(int n,int m); (2)设计四个类分别实现此接口,完成+-*/运算 ...
- Swift 函数做参数和闭包做参数的一个细节差别
函数作参数,示例为传入一个String和一个添加前缀的函数,返回一个添加完前缀的String: func demo(str:String,addPrefix:(String)->String)- ...
- 关于C#的Main(String[] args)参数输入问题
关于C#的Main(String[] args)参数输入问题 指定相关的测试代码 首先,写一个用于测试的关于Main(String[] args)参数输入有关的代码类,如下: using System ...
- switch的穿透,是参数里包含case内容就执行。
package rom; import java.lang.*; /* * switch的穿透,是参数里包含case内容就执行. */ public class Xamle_5 { public st ...
- python 将中文转拼音后填充到url做参数并写入excel
闲着没事写了个小工具,将中文转拼音后填充到url做参数并写如excel 一.先看下演示,是个什么东西 二.代码 代码用到一个中文转拼音的库,库是网上下的,稍微做了下修改,已经找不原来下载的地址了,然后 ...
随机推荐
- fake gucci outlet perform a couple associated with things in great trust
Based on my a lot of years of encounter within Taobao, purchase bags must go to the high reputation ...
- c++ redis-client
http://hahaya.github.io/operator-redis-under-linux/#0-tsina-1-10809-397232819ff9a47a7b7e80a40613cfe1 ...
- DotSpatial 删除图层要素
//添加图层后,定义图层,并获取图层 //遍历要素,并进行删除 FeatureSet fs = null; fs = (FeatureSet) map1.Layers[0].DataSet; //要素 ...
- X3850M2安装CertOS 7 KVM 2--VNC
需要安装远程桌面,否则无鼠标的日子比较难. VNC的安装需要步骤较多,重点参考以下文章: http://www.itzgeek.com/how-tos/linux/centos-how-tos/con ...
- mvc 导入,导出excel
最近主要做导入excel 在网上查询了代码 public FileResult DownLoadExcelJiZuChaXunGenRenXiaoFeiJiLu() { DataTable dt = ...
- weixin 公众平台开发
http://www.cnblogs.com/szw/archive/2013/05/14/weixin-course-index.html http://weixin.senparc.com/
- C语言状态机模板
转载声明:如果转载本博客内容,请联系869119842@qq.com,获得作者书面授权. 前言 上一篇我的博客中探讨了一种非swtich-case结构的状态机写法,但是个人感觉写起来比较麻烦,如果增加 ...
- clojure 之 hello world
1. 安装Leiningen 2. lein new app bar 3. lein run Hello, World!
- centos7下安装mantis
1.环境配置 Web Server:Apache,The web server must support PHP. 数据库:MySQL (or one of its forks, e.g. Maria ...
- 使用spring @Scheduled注解执行定时任务、
http://blog.csdn.net/sd4000784/article/details/7745947,留下来备用.