[
https://issues.apache.org/jira/browse/GROOVY-10938?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17689167#comment-17689167
]
Eric Milles edited comment on GROOVY-10938 at 2/15/23 2:45 PM:
---------------------------------------------------------------
These sorts of assignments were not type-checked properly prior to Groovy 4.
You can do "array_of_string = list_of_string as String[]" in Groovy 3. Or make
use of the verious "toArray" overloads.
In your example, you use collect to create a shallow copy. You can do "data =
data.clone()" for an efficient array copy.
was (Author: emilles):
These sorts of assignments were not type-checked properly prior to Groovy 4.
You can do "list_of_string = array_of_string as String[]" in Groovy 3. Or make
use of the verious "toArray" overloads.
> Cannot assign list to array under static compilation
> ----------------------------------------------------
>
> Key: GROOVY-10938
> URL: https://issues.apache.org/jira/browse/GROOVY-10938
> Project: Groovy
> Issue Type: Bug
> Components: Compiler
> Affects Versions: 3.0.15
> Reporter: Jason Garrett
> Priority: Minor
> Fix For: 4.x
>
>
> Assigning a List to an Array of the same type does not compile.
> This class:
> {code:java}
> package example
> import groovy.transform.CompileStatic
> @CompileStatic
> class AssignListToArray {
> void doStuff(String[] data) {
> data = data.collect { it }
> }
> } {code}
> Results in this compilation error:
> {code:java}
> src/main/groovy/example/AssignListToArray.groovy: 8: [Static type checking] -
> Cannot assign value of type java.util.List <java.lang.String> to variable of
> type java.lang.String[]
> @ line 8, column 10.
> data = data.collect { it } {code}
> This class compiles in 2.4.21, 2.5.21, and 3.0.14.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)