You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2025/05/12 14:22:00 UTC
[jira] [Resolved] (GROOVY-11616) Functions that take var args will default the type of the first argument, java tries to find the common parent type from all arguments
[ https://issues.apache.org/jira/browse/GROOVY-11616?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Eric Milles resolved GROOVY-11616.
----------------------------------
Fix Version/s: 5.0.0-beta-1
Resolution: Fixed
> Functions that take var args will default the type of the first argument, java tries to find the common parent type from all arguments
> --------------------------------------------------------------------------------------------------------------------------------------
>
> Key: GROOVY-11616
> URL: https://issues.apache.org/jira/browse/GROOVY-11616
> Project: Groovy
> Issue Type: Bug
> Components: Static Type Checker
> Affects Versions: 4.0.24, 5.0.0-alpha-12
> Reporter: Saravanan
> Assignee: Eric Milles
> Priority: Minor
> Fix For: 5.0.0-beta-1
>
>
>
> {code:java}
> public class Interfaces {
> class Blah {
> }
> class BlahBlah extends Blah {
> }
> class BlahBlahBlah extends Blah {
> }
> public String myThing() {
> // This fails with
> // Incompatible generic argument types. Cannot assign java.util.List<? extends com.org.interfaces.Interfaces.Blah>
> // to: java.util.List<com.org.interfaces.Interfaces.Blah>
> // To fix change to explicitly define generic type
> // Arrays.<Blah> asList(...)
> List<Blah> myArray = Arrays.asList(new Blah(), new BlahBlah(), new BlahBlahBlah(), new Blah());
> }
> }
> {code}
> Arrays.asList takes a vararg parameter. Groovy defaults to assuming that the first parameter type is the type (or parent type) for all parameters that follow. If we use instances of multiple derived types, Groovy errors out without trying to find the common parent type
--
This message was sent by Atlassian Jira
(v8.20.10#820010)