Change Groovy switch statement
PreviousUpgrading your scripts for Groovy 3 compatibilityNextAdjusting for Groovy JavaBeans specification compatibility changes
Last updated
Was this helpful?
Was this helpful?
def result = ""
switch(yourVariable) {
default:
result += "default "
// as there is no break statement, "case a" will be executed next
case 'a':
result += "a "
// as there is no break statement, "case b" will be executed next
case 'b':
result += "b"
}def result = ""
switch(yourVariable) {
case 'a':
result = "a b"
break
case 'b':
result = "b"
break
default:
result = "default a b"
break
}