Why does the Collections class contain standalone (static) methods, instead of them being added to the List interface?

前端 未结 5 1842
时光取名叫无心
时光取名叫无心 2021-02-19 11:41

For all the methods in Collections that take a List as their first argument, why aren\'t those methods simply part of the List interface?

My intuition is: given a List

5条回答
  •  终归单人心
    2021-02-19 12:12

    They are utility methods and not core List functionality. The List interface would just get bloated if you added every possible operation you could do on a List. And the operations in Collections do not need to know about the internals of a List, they operate on the public interface so can happily live in an external class.

提交回复
热议问题