Use string in switch case in java(在java中的switch case中使用字符串)
问题描述
在检查 String
时,我需要将以下 if
更改为 switch
-case
, 以提高圈复杂度.
I need to change the following if
's to a switch
-case
while checking for a String
, to improve the cyclomatic complexity.
但我不确定我会得到什么价值.
But I am not sure what value I'm going to get.
推荐答案
Java(版本 7 之前)在 switch/case 中不支持 String.但是您可以通过使用枚举来实现所需的结果.
Java (before version 7) does not support String in switch/case. But you can achieve the desired result by using an enum.
这篇关于在java中的switch case中使用字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!