org.codehaus.groovy.runtime.DefaultGroovyMethods public static boolean isCase(Pattern caseValue, Object switchValue) { if (switchValue == null) { return caseValue == null; } final Matcher matcher = caseValue.matcher(switchValue.toString()); if (matcher.matches()) { RegexSupport.setLastMatcher(matcher); return true; } else { return false; } } org.codehaus.groovy.runtime.ScriptBytecodeAdapter public static boolean isCase(Object switchValue, Object caseExpression) throws Throwable{ if (caseExpression == null) { return switchValue == null; } return asBool(invokeMethod(caseExpression, "isCase", new Object[]{switchValue})); } SwitchTest.groovy void testSwitch() { callSwitch("foo", "foo") callSwitch("bar", "barfoo") callSwitch("dummy", "d*") callSwitch("xyz", "xyzDefault") callSwitch("zzz", "Default") callSwitch(4, "List") callSwitch(5, "List") callSwitch(6, "List") callSwitch("inList", "List") callSwitch(1, "Integer") callSwitch(1.2, "Number") callSwitch(null, "null") } def callSwitch(x, expected) { println("Calling switch with ${x}") def result = "" switch (x) { case null: result = "null" break case ~/d.*/: result = "d*" break case "bar": result = result + "bar" case "foo": result = result + "foo" break case [4, 5, 6, 'inList']: result = "List" break case Integer: result = "Integer" break case Number: result = "Number" break case "xyz": result = result + "xyz" default: result = result + "Default" // unnecessary just testing compiler break; } println("Found result ${result}") assert result == expected , "when calling switch with ${x}" }