Please have a look at the following class... The complier throws error in the mentioned line... but, i am not able to understand why
public class Wildcards {
public static void main(
String[] args) {
List<Shape> data = new ArrayList<Shape>();
update(data);
}
public static void update(Collection<? extends Shape> values) {
values.add(new Shape()); //Compiler error
}
static class Shape {}
static class Circle extends Shape {}
static class Square extends Shape {}
}
The error is:
The method add(capture-of ? extends Wildcards.Shape) in the type Collection<capture-of ? extends Wildcards.Shape> is not applicable for the arguments (Wildcards.Shape).
Thanks,
Sudhakar R