在groovy中支持如下 条件语句
1:if/else if/else
if ( ... ) {
...
} else if (...) {
...
} else {
...
}
2:switch / case
Groovy中的switch语句向后兼容Java代码
Switch supports the following kinds of comparisons:
-
Class case values match if the switch value is an instance of the class
-
Regular expression case values match if the
toString()
representation of the switch value matches the regex -
Collection case values match if the switch value is contained in the collection. This also includes ranges (since they are Lists)
-
Closure case values match if the calling the closure returns a result which is true according to the Groovy truth
-
If none of the above are used then the case value matches if the case value equals the switch value
switch