Hi,

lists and arrays are different in Groovy. As already pointed out a array
is strictly limited by a certain length, while a List is not
necessarily. This behavior is quite old, from I think even before I
joined the project back in the pre Groovy 1.0 phase.

Groovy is actually using a mix from other languages for list. The
Javascript List for example allows accessing indexes beyond the maximum
length for writing and reading. The negative index usage on the other
hand comes from Python.

Javascript though has no List, they are Arrays and Python has no Arrays,
there are only lists... Groovy and Java have both, and we decided to
move away from the Java semantics in this. I never found a need to
change this actually.

Then String... well... the pov is that String is like an array of
char/codepoints and therefore does exhibit Groovy array behaviour.

But you all are right, that we really lack a more in depth description
of this.

bye Jochen




On 06.02.25 10:20, OCsite wrote:
Hi there,

is this inconsistence intentional and the proper Groovy behaviour, or is
that a bug and should I add a jira ticket?

Thanks!

===

*groovy:*000*>* a=[1,2]

*===>* [1, 2]

*groovy:*000*>* b=a as Object[]

*===>* [1, 2]

*groovy:*000*>* a[2]

*===>* null

*groovy:*000*>* b[2]

*ERROR*java.lang.ArrayIndexOutOfBoundsException:

*Index 2 out of bounds for length 2*

*groovy:*000*>*

===

Reply via email to