Difference between Enumeration<? extends ZipEntry> and Enumeration?

后端 未结 3 1421
青春惊慌失措
青春惊慌失措 2021-01-02 06:19

Is there a difference between Enumeration and Enumeration? If so, what is the difference?

3条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-02 07:05

    Yes, straight from one of the sun generics tutorials:

    Here Shape is an abstract class with three subclasses: Circle, Rectangle, and Triangle.

    public void draw(List shape) {
      for(Shape s: shape) {
        s.draw(this);
      }
    }
    

    It is worth noting that the draw() method can only be called on lists of Shape and cannot be called on a list of Circle, Rectangle, and Triangle for example. In order to have the method accept any kind of shape, it should be written as follows:

    public void draw(List shape) {
       // rest of the code is the same
    }
    

提交回复
热议问题