Saravanan created GROOVY-11616:
----------------------------------
Summary: 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: Compiler, Static compilation
Affects Versions: 4.0.24
Reporter: Saravanan
{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)