I just found that code:
[1,2] [4, 4]
is completely valid in Groovy but can’t find what does such expression evaluates to, for me it returns null in all possible cases:
groovy:000> [1, 2] []
===> []
groovy:000> [1, 2] [4]
===> null
groovy:000> [1, 2] [4,5]
===> [null, null]
So basically the question is what does the expression:
a = list1 list2
mean in Groovy?
In groovy, the
[]operator is just a shorthand forgetAt(), so in this case it’s calling the methodList.getAt(Collection).The behavior is to return a list containing all the elements whose index is listed in the collection. So for
[1,2][4,5], it’s returning a list with elements 4 and 5, which both happen to be out of range, so null.Here are some examples that illustrate it a little better: