泛型通配符:泛型上限通配符? extends 上限类型

格式: ? extends 上限类型

public abstract class Shape {
 public abstract void draw(Canvas c);
}

public class Circle extends Shape{

 @Override  public void draw(Canvas c) {   // TODO Auto-generated method stub     }   }

public class Rectangle extends Shape{

 @Override  public void draw(Canvas c) {   // TODO Auto-generated method stub     }

}

public class Canvas {
 public void drawAll(List<? extends Shape> shapes){
  for(Shape s:shapes){
   s.draw(this);
  }
 }
}

posted @ 2013-02-21 09:39  IamThat  阅读(226)  评论(0编辑  收藏  举报