We have been stepping in Java-style array syntax starting in Groovy 3. The
next step of this support is the terse initialization syntax:
int[][] matrix = { {1}, {2}, {3} }
Without this change, a multi-dimensional array expression requires "new int[]"
for each sub-array. Or falling back to square-bracket notation.
As discussed in GROOVY-8561, there is one edge case that results in a breaking
change. When a single value is provided for an array declaration, the value is
wrapped in an array implicitly: int[] a = 1
The conflict comes when the type supports a closure literal:
Closure [] a = {}
Runnable[] b = {}
String [] c = { print(it) } // not sure what this is for
This can be disambiguated with the addition of an arrow:
Closure [] a = { -> }
Runnable[] b = { -> }
String [] c = { x -> print(x) }
I have made note of this in the COMPATIBILITY document and I don't think this
pattern is in common usage.
Do you have any comments on the risk of this breaking change? Or do you think
it is necessary to support array promotion for arrowless closures?
This change is implemented here: https://github.com/apache/groovy/pull/3054
And was originally proposed here: https://github.com/apache/groovy/pull/691
This e-mail is for the sole use of the intended recipient and contains
information that may be privileged and/or confidential. If you are not an
intended recipient, please notify the sender by return e-mail and delete this
e-mail and any attachments. Certain required legal entity disclosures can be
accessed on our website:
https://www.thomsonreuters.com/en/resources/disclosures.html