Can Some one please explain why the line no. 12 gives a compile time error ?
package com.soflow;
import java.util.List;
public abstract class Shape {
}
class Rectangle extends Shape {
private int x, y, width, height;
public void addRectangle(List<? extends Shape> shapes) {
shapes.add(0, new Rectangle()); // compile-time error!
}
}
What I am failing to understand here is that why is it not allowing me to add a subtype of shapes into the "shapes" list ? And why is it complaining at compile time ? I believe compiler can see that there exists an IS-A relation between Rectangle and Shape. I am confused now. Any help is greatly appreciated.
Thanks, Maneesh Sharma
Any help will be appreciated