Home  >  Q&A  >  body text

java的List接口中为什么要包含所有Collection接口中的方法?

java的List接口中为什么要包含所有Collection接口中的方法?

不是已经继承Collection接口了, 为什么还要再写一遍?

PHP中文网PHP中文网2741 days ago531

reply all(3)I'll reply

  • 巴扎黑

    巴扎黑2017-04-18 09:27:38

    1. Improve the interface. The functions carried by the same interface of Collection and List are not exactly the same.

      Collection中的add 只是保证容器中包含参数对象。
      List中的add 将参数对象保存到容器的末尾。
    2. Improving the documentation is somewhat related to the first point.

    reply
    0
  • 天蓬老师

    天蓬老师2017-04-18 09:27:38

    In fact, this may be just a practice of Java developers.
    Usually our requirements will say which interfaces a certain class needs to implement, but in fact, if we take the trouble to find the mutual dependencies of these interfaces and then exclude duplicate projects, the process is cumbersome, and these duplicates will also be compiled during compilation. automatically processed. So these people directly write the classes that are required to be implemented, eliminating the trouble of manual deduplication.

    reply
    0
  • 阿神

    阿神2017-04-18 09:27:38

    If there are N levels of inheritance, then you have to find the lowest interface method all the time

    reply
    0
  • Cancelreply