Wednesday, March 29, 2017

A Groovy switch case example

A Groovy switch case example


Below is an example of Groovys switch/case feature taken from The Definitive Guide to Grails by Graeme Rocher. I am not a regular user of Javas switch/case feature, but if it had been this way perhaps I might have.

switch (x) {
case James:
println "yes it is me"
break
case 18..65:
println "ok you are old"
break
case ~/Gw?+e/:
println "your name starts with G and ends in e!"
break
case Date:
println got a Date instance
break
case [John, Ringo, Paul, George]:
println "Got one of the Beatles"
break
default:
println "Dont know"
}


Available link for download