我知道在Java中,当你只有几个情况时,不应使用switch语句,而应该使用if else if
语句。
那么在groovy中也是这样吗?
这两种代码哪个更高效?
myBeans.each{
switch it.name
case 'aValue':
//some operation
case 'anotherValue:
//other operations
}
或者:
myBeans.each{
if(it.name == 'aValue'){
//some operation
}
else if (it.name =='anotherValue){
//other operations
}
}