Re: [Poll] About supporting Java-like array

2018-04-29 Thread Paul King
That sounds like a limitation we'd like to remove when using @CompileStatic. Want to create a Jira? Cheers, Paul. On Mon, Apr 30, 2018 at 12:39 PM, MG wrote: > Hi Daniel, > > I did a quick check and it works with dynamic Groovy, but is rejected > under static compilation: >

Re: [Poll] About supporting Java-like array

2018-04-29 Thread MG
Hi Daniel, I did a quick check and it works with dynamic Groovy, but is rejected under static compilation: @Test @Ignore void arrayFromListLiteral() { int[] a0 = [1,2,3] int[][] aa0 = [[1,2,3],[4,5,6]] int[][][] aaa0 = [[[1],[2],[3]],[[4],[5],[6]]] int[][][] aaa1 = [[1,2,3],[4,5,6]]

Re: [Poll] About supporting Java-like array

2018-04-29 Thread Daniel Sun
Hi mg, As far as I remember, two dimensional array like`int[][] a = [[1, 2, 3], [4, 5, 6]]` will go wrong in the Groovy style. Cheers, Daniel.Sun -- Sent from: http://groovy.329449.n5.nabble.com/Groovy-Users-f329450.html

Re: [Poll] About supporting Java-like array

2018-04-29 Thread Paul King
On Mon, Apr 30, 2018 at 9:10 AM, mg wrote: > I would propose the Groovy compiler issue a warning to change the array > initialization from Java- to Groovy-style then... > A codenarc rule would be a great first option. > Cheers, > mg > > > > Ursprüngliche Nachricht

Re: [Poll] About supporting Java-like array

2018-04-29 Thread mg
Well tickle my belly and colour me green - I always thought using the "as" form was mandatory here (based on the examples I saw on the net back then) :-) That means this is the one case where giving an explicit type is the most concise way to get what you want ;-) I would propose the Groovy

Re: [Poll] About supporting Java-like array

2018-04-29 Thread Paul King
Yes, what you suggested is supported and indeed the preferred way. The `as int[]` is only needed if you have def at the front, e.g.: def fibs = [1, 1, 2, 3, 5, 8] as int[] Cheers, Paul. On Mon, Apr 30, 2018 at 7:54 AM, Keith Suderman wrote: > I am always +1 on supporting

Re: [Poll] About supporting Java-like array

2018-04-29 Thread Keith Suderman
I am always +1 on supporting Java syntax when practical. > On Apr 29, 2018, at 5:17 PM, MG wrote: > > 2) I feel { { } } being interpreted as an array containing an empty closure > is confusing, i.e. not least surprise. I would rather not see it cut it so > close with

Re: [Poll] About supporting Java-like array

2018-04-29 Thread MG
After thinking about this some more for the last weeks +1 with asterisk from my side: 1) I am always for being as Java compatible as possible (though I see that this might not be feasible in all cases in the future, due to Java changing at a much faster pace and with more syntax changes now

Re: [Poll] About supporting Java-like array

2018-04-29 Thread Paul King
+1 For completeness, I added some more details about the breaking changes and workarounds into the issue - included below for easy reading. Cheers, Paul. = Groovy currently "promotes" a singleton instance of an object into an array for assignments, e.g.: Integer[] nums = 42

[Poll] About supporting Java-like array

2018-04-29 Thread Daniel.Sun
Hi all, As we all know, Java array is one of features widely applied in Java projects. In order to improve the compatibility with Java(Copy & Paste). The PR[1] will make Groovy support java-like array and make the differences[2] with Java less and less, e.g. *One-Dimensional array* ```