Eingeschränkte Typ-Argumente

interface Shape { 
  void draw (Canvas c);
}
class Circle implements Shape { .. }
class Rectangle implements Shape { .. }
Das folgende
void drawAll (List<Shape> xs) {
   for (Shape x : xs) { x.draw (this); }
}
ist nicht auf List<Circle> anwendbar!

Besser:

void drawAll (List<S extends Shape> xs) {
   for (S x : xs) { x.draw (this); }
}


Johannes Waldmann 2004-11-30