2.<? extends T>表示所有T的子类都可以当成参数传递,<? super T>表示s所有 T 以及T的父类都能够当做参数传递作者: 肖岑锋 时间: 2011-11-22 21:53
楼上正解。下面是一个应用
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); }
}