java的List接口中为什么要包含所有Collection接口中的方法?
PHP中文网
PHP中文网 2017-04-18 09:25:38
0
3
522

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

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

PHP中文网
PHP中文网

认证高级PHP讲师

reply all(3)
巴扎黑
  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.

Peter_Zhu

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.

阿神

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!