• 周五. 3月 29th, 2024

5G编程聚合网

5G时代下一个聚合的编程学习网

热门标签

switch的使用

admin

11月 28, 2021

ji本没用过这个函数,今天用到了它,发现了一些使用要注意的地方:

switch的参数支持int和枚举,单jdk1.7后,开始支持String类型。我特意在jdk1.8上试了试,

public class SwitchTest {
public static void main (String [] args){
String a="1";
switch (a){
case "1":System.out.println("ok"); break;
default:System.out.println("no");
}

}
}

结果如下:

Connected to the target VM, address: ‘127.0.0.1:60125’, transport: ‘socket’
ok
Disconnected from the target VM, address: ‘127.0.0.1:60125’, transport: ‘socket’

Process finished with exit code 0

说明,没问题;

在jdk1.7以下的版本人会提示参数不可使用String类型。

没踩过的坑,有时候踩一下,才踏实。



《switch的使用》有一个想法
  1. Wow, marvelous blog structure! How long have you ever been blogging for?
    you made running a blog glance easy. The entire look of
    your site is excellent, let alone the content material! You can see
    similar here najlepszy sklep

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注