楼上正解。下面是一个应用
public abstract class Shape{
public abstract void draw(Canvas c);
}
public class Circle extend Shape{
public void draw(Canvas c){
}
}
public class Canvas{
public void drawAll(List<? extends Shape>){
for(Shape s : shapes){
s.draw(this);
}
}
public static void main(String[] args){
List<Circle> circleList = new ArrayList<Circle>;
circleList.add(new Circle);
Canvas c = new Canvas;
c.drawAll(circleList); }
} |