groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "KARR, DAVID" <dk0...@att.com>
Subject Curious that Groovy case can match values that are not equal to the candidate
Date Fri, 07 Aug 2015 21:05:02 GMT
Reading REGINA, I find this detail of Groovy semantics very curious:
----------------------
def myList = ['a', 'b', 'c']
switch ('c') {
case myList: assert true;break;
default: assert false;break;
}
--------------

In all the languages I'm aware of with some sort of "switch/case" construct, you can always
assume that if the "case" matches, then the "case" value "is equal to" the switch candidate.
 This is the first time I've seen this not be the case.

I certainly understand what Groovy is doing here, and I appreciate the power of it, it's just
a bit surprising.

Mime
View raw message