The Groovy \"in\" operator seems to mean different things in different cases. Sometimes x in y
means y.contains(x)
and sometimes it seems to call
in
is the "Membership operator".
From the documentation for Groovy 3 (emphasis mine):
8.6. Membership operator
The membership operator (
in
) is equivalent to calling theisCase
method. In the context of aList
, it is equivalent to callingcontains
, like in the following example:def list = ['Grace','Rob','Emmy'] assert ('Emmy' in list) # (1)
(1)
equivalent to callinglist.contains('Emmy')
orlist.isCase('Emmy')
So, Groovy always calls isCase
, which in case of a List
maps to contains
.