Assuming this class hierarchy:
class A {}
class B extends class A {}
The following code is not valid in Java:
List<A> list = new ArrayList<B>();
Because ArrayList<B>
is not a subtype of List<A>
.
However, in groovy the code above does not seem to raise an error. Why is that?