You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Mauro Molinari (JIRA)" <ji...@apache.org> on 2015/07/16 15:55:04 UTC

[jira] [Created] (GROOVY-7506) Cannot assign value of type java.util.List to variable of type java.lang.String[]

Mauro Molinari created GROOVY-7506:
--------------------------------------

             Summary: Cannot assign value of type java.util.List<java.lang.String> to variable of type java.lang.String[]
                 Key: GROOVY-7506
                 URL: https://issues.apache.org/jira/browse/GROOVY-7506
             Project: Groovy
          Issue Type: Bug
          Components: Static Type Checker
    Affects Versions: 2.4.4, 2.4.3
            Reporter: Mauro Molinari
            Assignee: Cédric Champeau


Usually the static type checker is smart enough to accept a {{List<String>}} to be assigned to a {{String[]}} variable, however in this particular case it is not:

{code:title=Wrapper.java}
package test;

public class Wrapper {
	String[] wrapped;
	
	public Wrapper(String[] wrapped) {
		this.wrapped = wrapped;
	}
}
{code}

{code:title=Other.java}
package test;

public class Other {
	private Wrapper foo;
	
	public void setFoo(String... args) {
		this.foo = new Wrapper(args);
	}
}
{code}

{code:title=Test.groovy}
package test

import groovy.transform.CompileStatic

@CompileStatic
class Test {
	
	static test() {
		Other o = new Other()
		o.foo = ['foo', 'bar']
	}
}
{code}

The assignment to {{o.foo}} unexpectedly fails. However, if I declare the {{foo}} field and {{setFoo}} method directly in {{Test}}, and change the code to assign to {{t.foo}} (where {{t}} is of type {{Test}}), the type checking passes.

Please note that with Groovy 2.3.11 the assignment to {{o.foo}} was passing (no error produced by the static type checker!).



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)