[ https://issues.apache.org/jira/browse/GROOVY-11616?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17943928#comment-17943928 ]
Saravanan commented on GROOVY-11616: ------------------------------------ I see this now. It does look like Java considers the target variable List<Blah> instead of List<? extends Blah>. I think the groovy implementation is more accurate, but the java implementation is not wrong > 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 > Reporter: Saravanan > Priority: Minor > > > {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)